[gcc/devel/omp/gcc-9] Reduce code instantiated by filesystem::path::_S_convert_loc
Tobias Burnus
burnus@gcc.gnu.org
Thu Mar 5 13:59:00 GMT 2020
https://gcc.gnu.org/g:661fbea42f3614792f76c3f996d38e64d7e035d4
commit 661fbea42f3614792f76c3f996d38e64d7e035d4
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Jun 14 19:11:30 2019 +0100
Reduce code instantiated by filesystem::path::_S_convert_loc
Jakub noted in https://gcc.gnu.org/ml/libstdc++/2019-04/msg00140.html
that an unwanted std::wstring::_M_replace_dispatch symbol has started to
be exported from the Fedora shared library. This symbol is triggered by
the instantiation of std::wstring::assign(const char*, const char*) from
std::__str_codecvt_in which is called from path::_S_convert_loc. The
branch that triggers that instantiation can't actually happen in that
case, because codecvt facets will only return noconv when the input and
output types are the same. Guarding the assign call with an if-constexpr
check that the types are the same avoids instantiating template
specializations that will never actually be needed.
Backport from mainline
2019-04-26 Jonathan Wakely <jwakely@redhat.com>
* config/abi/pre/gnu.ver (GLIBCXX_3.4): Replace wildcard that matches
wstring::_M_replace_dispatch with more specific patterns.
* include/bits/fs_path.h (path::_S_convert_loc<_InputIterator>):
Create const std::string to avoid redundant call to _S_convert_loc
with non-const pointers.
* include/bits/locale_conv.h (__do_str_codecvt): Use if-constexpr to
avoid unnecessary basic_string::assign instantiations.
From-SVN: r272306
Diff:
---
libstdc++-v3/ChangeLog | 13 +++++++++++++
libstdc++-v3/include/bits/fs_path.h | 2 +-
libstdc++-v3/include/bits/locale_conv.h | 10 ++++++++--
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1f503c4..e9ed7ea 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -3,6 +3,19 @@
Backport from mainline
2019-04-26 Jonathan Wakely <jwakely@redhat.com>
+ * config/abi/pre/gnu.ver (GLIBCXX_3.4): Replace wildcard that matches
+ wstring::_M_replace_dispatch with more specific patterns.
+ * include/bits/fs_path.h (path::_S_convert_loc<_InputIterator>):
+ Create const std::string to avoid redundant call to _S_convert_loc
+ with non-const pointers.
+ * include/bits/locale_conv.h (__do_str_codecvt): Use if-constexpr to
+ avoid unnecessary basic_string::assign instantiations.
+
+2019-06-14 Jonathan Wakely <jwakely@redhat.com>
+
+ Backport from mainline
+ 2019-04-26 Jonathan Wakely <jwakely@redhat.com>
+
* include/experimental/bits/fs_path.h
(path::_S_convert_loc<_InputIterator>): Create const std::string to
avoid redundant call to _S_convert_loc with non-const pointers.
diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index ecef19e..0e07e23 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -539,7 +539,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_S_convert_loc(_InputIterator __src, __null_terminated,
const std::locale& __loc)
{
- std::string __s = _S_string_from_iter(__src);
+ const std::string __s = _S_string_from_iter(__src);
return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
}
diff --git a/libstdc++-v3/include/bits/locale_conv.h b/libstdc++-v3/include/bits/locale_conv.h
index d7510df..4cb9c39 100644
--- a/libstdc++-v3/include/bits/locale_conv.h
+++ b/libstdc++-v3/include/bits/locale_conv.h
@@ -88,8 +88,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__result == codecvt_base::noconv)
{
- __outstr.assign(__first, __last);
- __count = __last - __first;
+ // The codecvt facet will only return noconv when the types are
+ // the same, so avoid instantiating basic_string::assign otherwise
+ if _GLIBCXX17_CONSTEXPR (is_same<typename _Codecvt::intern_type,
+ typename _Codecvt::extern_type>())
+ {
+ __outstr.assign(__first, __last);
+ __count = __last - __first;
+ }
}
else
{
More information about the Libstdc++-cvs
mailing list