diff mbox series

[committed,v2] libstdc++: Optimize __try_use_facet for const types

Message ID 20240823124055.964684-1-jwakely@redhat.com
State New
Headers show
Series [committed,v2] libstdc++: Optimize __try_use_facet for const types | expand

Commit Message

Jonathan Wakely Aug. 23, 2024, 12:40 p.m. UTC
Tested x86_64-linux. Pushed to trunk.

-- >8 --

LWG 436 confirmed that const-qualified types are valid arguments for
Facet template parameters (but volatile-qualified types are not). Use the
fast path in std::use_facet and std::has_facet for const T as well as T.

libstdc++-v3/ChangeLog:

	* include/bits/locale_classes.tcc (__try_use_facet): Also avoid
	dynamic_cast for const-qualified facet types.
---
 libstdc++-v3/include/bits/locale_classes.tcc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc
index c79574e58de..d5ef1911057 100644
--- a/libstdc++-v3/include/bits/locale_classes.tcc
+++ b/libstdc++-v3/include/bits/locale_classes.tcc
@@ -110,7 +110,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       // We know these standard facets are always installed in every locale
       // so dynamic_cast always succeeds, just use static_cast instead.
 #define _GLIBCXX_STD_FACET(...) \
-      if _GLIBCXX_CONSTEXPR (__is_same(_Facet, __VA_ARGS__)) \
+      if _GLIBCXX_CONSTEXPR (__is_same(const _Facet, const __VA_ARGS__)) \
 	return static_cast<const _Facet*>(__facets[__i])
 
       _GLIBCXX_STD_FACET(ctype<char>);