libstdc++: Fix std::filesystem errors with -fkeep-inline-functions [PR108636]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 2 Feb 2023 14:06:40 +0000 (14:06 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 2 Feb 2023 16:18:37 +0000 (16:18 +0000)
commitdb8d6fc572ec316ccfcf70b1dffe3be0b1b37212
treeea8fc25ef24ac35e426926635afb33e6c87032c4
parent1395415fdc2d60e5346dbcf476749daf42d5b724
libstdc++: Fix std::filesystem errors with -fkeep-inline-functions [PR108636]

With -fkeep-inline-functions there are linker errors when including
<filesystem>. This happens because there are some filesystem::path
constructors defined inline which call non-exported functions defined in
the library. That's usually not a problem, because those constructors
are only called by code that's also inside the library. But when the
header is compiled with -fkeep-inline-functions those inline functions
are emitted even though they aren't called. That then creates an
undefined reference to the other library internsl. The fix is to just
move the private constructors into the library where they are called.
That way they are never even seen by users, and so not compiled even if
-fkeep-inline-functions is used.

On trunk there is a second problem, which is that the new equality
operators for comparing directory iterators with default_sentinel use
the shared_ptr::operator bool() conversion operator. The shared_ptr
specializations used by directory iterators are explicitly instantiated
in the library, but the bool conversion operators are not exported. This
causes linker errors at -O0 or with -fkeep-inline-functions. That just
requires the conversion operators to be exported.

libstdc++-v3/ChangeLog:

PR libstdc++/108636
* config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export shared_ptr
conversion operators for directory iterator comparisons with
std::default_sentinel_t.
* include/bits/fs_path.h (path::path(string_view, _Type))
(path::_Cmpt::_Cmpt(string_view, _Type, size_t)): Move inline
definitions to ...
* src/c++17/fs_path.cc: ... here.
* testsuite/27_io/filesystem/path/108636.cc: New test.
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/src/c++17/fs_path.cc
libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc [new file with mode: 0644]