]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add assertion for valid facet type arguments
authorJonathan Wakely <jwakely@redhat.com>
Wed, 22 May 2024 15:49:31 +0000 (16:49 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Sun, 15 Sep 2024 15:15:28 +0000 (16:15 +0100)
LWG 436 confirmed that const-qualified types are valid arguments for
Facet template parameters, but volatile-qualified types are not.  Add an
assertion to locale::combine to check for valid types.

libstdc++-v3/ChangeLog:

* include/bits/locale_classes.h (__is_facet): New helper.
* include/bits/locale_classes.tcc (locale::combine): Check that
_Facet type is valid.

libstdc++-v3/include/bits/locale_classes.h
libstdc++-v3/include/bits/locale_classes.tcc

index 50a748066f190866a5b0cd49c48a116e115a35c9..e168881b516277ac64183df1020cd32883fd1767 100644 (file)
@@ -381,6 +381,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
   };
 
+#if __cpp_lib_type_trait_variable_templates // C++ >= 17
+  template<typename _Tp>
+    constexpr bool __is_facet = is_base_of_v<locale::facet, _Tp>;
+  template<typename _Tp>
+    constexpr bool __is_facet<volatile _Tp> = false;
+#endif
 
   // 22.1.1.1.2  Class locale::facet
   /**
index d5ef1911057b85be59c1fcc15a0fb3ba02480ae6..1b5f5f2417c83dc5a009c0bfe6a8899ea06b061f 100644 (file)
@@ -71,6 +71,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     locale::
     combine(const locale& __other) const
     {
+#if __cpp_lib_type_trait_variable_templates // C++ >= 17
+      static_assert(__is_facet<_Facet>, "Template argument must be a facet");
+#endif
+
       _Impl* __tmp = new _Impl(*_M_impl, 1);
       __try
        {