https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117813
Bug ID: 117813 Summary: GCC14 + -fsanitize=undefined + -Os + recursive_directory_iterator results in undefined reference Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jan.brzezanski at gmail dot com Target Milestone: --- Created attachment 59726 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59726&action=edit Minimal testcase source file Hi! I've encountered an issue when compiling even minimal program that uses std::filesystem::recursive_directory_iterator with GCC14 (either 14.1.0 or 14.2.0) with both -fsanitize=undefined and -Os set. Simple testcase (attached) has been compiled just with `g++ -fsanitize=undefined -Os main.cpp` command. Error message is: main.cpp:(.text.startup+0x137): undefined reference to `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()' collect2: error: ld returned 1 exit status I've reproduced it with fresh gcc downloaded from ftp and built without any special configure options on x86_64-pc-linux-gnu machine. Change of either one of those 3: compiler/sanitizer/optimization will result in correct behaviour: - gcc 13.3.0 built in the same way passes the test - changing -fsanitize=undefined/-Os to any other sanitizer/optimization level will also make the test pass >From my observation, an intermediate object ends up with symbol that is not present in libstdc++.so and thus linking fails. Best Regards, Jan