From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id BA0533858D28; Thu, 16 Mar 2023 17:53:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA0533858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678989223; bh=rgtZOU6P4/HC3FOlK6DVj+pEa3Dq2ckupJCuSb+I9Hg=; h=From:To:Subject:Date:From; b=rfCNfNuFvb3zCOBPksscNQoZXPxvQFdXkb8Dso/jvOwltwgULKrLLTu+EhvUpUHg9 PwEWEjG1oLXwg6U4a/nylIlGjZo7rjFxiZuYubQDWi6wy8RFdJ4nm+DG7GNIu1rI4n t9FWI66xn9WPk0iTxdqtqUW/Pb7md6o/DDCRzBT8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-11253] libstdc++: Fix std::filesystem errors with -fkeep-inline-functions [PR108636] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 5d9958d5637cc4f0a6e09e244cbf8565cffd8ba6 X-Git-Newrev: d640e435f156d8f825bf95c2164053b4a3a7b682 Message-Id: <20230316175343.BA0533858D28@sourceware.org> Date: Thu, 16 Mar 2023 17:53:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d640e435f156d8f825bf95c2164053b4a3a7b682 commit r10-11253-gd640e435f156d8f825bf95c2164053b4a3a7b682 Author: Jonathan Wakely Date: Thu Feb 2 14:06:40 2023 +0000 libstdc++: Fix std::filesystem errors with -fkeep-inline-functions [PR108636] With -fkeep-inline-functions there are linker errors when including . 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 internals. 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) Diff: --- libstdc++-v3/include/bits/fs_path.h | 10 ++-------- libstdc++-v3/src/c++17/fs_path.cc | 13 +++++++++++++ libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc | 8 ++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 7b49461794f..3370bf7161e 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -515,12 +515,7 @@ namespace __detail _Multi = 0, _Root_name, _Root_dir, _Filename }; - path(basic_string_view __str, _Type __type) - : _M_pathname(__str) - { - __glibcxx_assert(__type != _Type::_Multi); - _M_cmpts.type(__type); - } + path(basic_string_view __str, _Type __type); enum class _Split { _Stem, _Extension }; @@ -766,8 +761,7 @@ namespace __detail struct path::_Cmpt : path { - _Cmpt(basic_string_view __s, _Type __t, size_t __pos) - : path(__s, __t), _M_pos(__pos) { } + _Cmpt(basic_string_view __s, _Type __t, size_t __pos); _Cmpt() : _M_pos(-1) { } diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc index 812f39fe253..9d945ed07a8 100644 --- a/libstdc++-v3/src/c++17/fs_path.cc +++ b/libstdc++-v3/src/c++17/fs_path.cc @@ -186,6 +186,19 @@ struct path::_Parser { return origin + c.str.data() - input.data(); } }; +inline +path::path(basic_string_view __str, _Type __type) +: _M_pathname(__str) +{ + __glibcxx_assert(__type != _Type::_Multi); + _M_cmpts.type(__type); +} + +inline +path::_Cmpt::_Cmpt(basic_string_view __s, _Type __t, size_t __pos) +: path(__s, __t), _M_pos(__pos) +{ } + struct path::_List::_Impl { using value_type = _Cmpt; diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc new file mode 100644 index 00000000000..d58de461090 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc @@ -0,0 +1,8 @@ +// { dg-do link { target c++17 } } +// { dg-options "-fkeep-inline-functions" } + +#include +int main() +{ + // PR libstdc++/108636 - link failure with -fkeep-inline-functions +}