https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114553

            Bug ID: 114553
           Summary: Undefined symbol in directory_iterator move assignment
                    operator with -Os
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: toni.lammi at kone dot com
  Target Milestone: ---

Created attachment 57842
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57842&action=edit
save-temps

Compiling code containing std::directory_iterator move assignment fails when
-Os option is passed. The build was performed in Manjaro Linux.

This happens with both GNU ld and mold linkers:
$ g++ -save-temps -std=c++20 -Os -o gcc_err ./gcc_err.cpp
/usr/bin/ld: gcc_err.o: in function `main':
gcc_err.cpp:(.text.startup+0x3f): undefined reference to
`std::__shared_ptr<std::filesystem::__cxx11::_Dir,
(__gnu_cxx::_Lock_policy)2>::swap(std::__shared_ptr<std::filesystem::__cxx11::_Dir,
(__gnu_cxx::_Lock_policy)2>&)'
collect2: error: ld returned 1 exit status

$ g++ -std=c++20 -Os -o gcc_err -fuse-ld=mold ./gcc_err.cpp 
mold: error: undefined symbol:
std::__shared_ptr<std::filesystem::__cxx11::_Dir,
(__gnu_cxx::_Lock_policy)2>::swap(std::__shared_ptr<std::filesystem::__cxx11::_Dir,
(__gnu_cxx::_Lock_policy)2>&)
>>> referenced by gcc_err.cpp
>>>               gcc_err.o:(main)
collect2: error: ld returned 1 exit status

When not optimizing for size everything works fine:
$ g++ -std=c++20 -O3 -o gcc_err ./gcc_err.cpp


In compiler explorer (https://godbolt.org/) I can replicate this with g++
versions 13.2, 12.3 and 11.4. The issue does not seem to be present in trunk.

Reply via email to