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.
libstdc++-v3/ChangeLog:
PR libstdc++/108636
* 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.
(cherry picked from commit
db8d6fc572ec316ccfcf70b1dffe3be0b1b37212)
_Multi = 0, _Root_name, _Root_dir, _Filename
};
- path(basic_string_view<value_type> __str, _Type __type)
- : _M_pathname(__str)
- {
- __glibcxx_assert(__type != _Type::_Multi);
- _M_cmpts.type(__type);
- }
+ path(basic_string_view<value_type> __str, _Type __type);
enum class _Split { _Stem, _Extension };
struct path::_Cmpt : path
{
- _Cmpt(basic_string_view<value_type> __s, _Type __t, size_t __pos)
- : path(__s, __t), _M_pos(__pos) { }
+ _Cmpt(basic_string_view<value_type> __s, _Type __t, size_t __pos);
_Cmpt() : _M_pos(-1) { }
{ return origin + c.str.data() - input.data(); }
};
+inline
+path::path(basic_string_view<value_type> __str, _Type __type)
+: _M_pathname(__str)
+{
+ __glibcxx_assert(__type != _Type::_Multi);
+ _M_cmpts.type(__type);
+}
+
+inline
+path::_Cmpt::_Cmpt(basic_string_view<value_type> __s, _Type __t, size_t __pos)
+: path(__s, __t), _M_pos(__pos)
+{ }
+
struct path::_List::_Impl
{
using value_type = _Cmpt;
--- /dev/null
+// { dg-do link { target c++17 } }
+// { dg-options "-fkeep-inline-functions" }
+
+#include <filesystem>
+int main()
+{
+ // PR libstdc++/108636 - link failure with -fkeep-inline-functions
+}