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. 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 | 6 ++++++
libstdc++-v3/include/bits/locale_classes.tcc | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/libstdc++-v3/include/bits/locale_classes.h
b/libstdc++-v3/include/bits/locale_classes.h
index 50a748066f1..e168881b516 100644
--- a/libstdc++-v3/include/bits/locale_classes.h
+++ b/libstdc++-v3/include/bits/locale_classes.h
@@ -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
/**
diff --git a/libstdc++-v3/include/bits/locale_classes.tcc
b/libstdc++-v3/include/bits/locale_classes.tcc
index d5ef1911057..1b5f5f2417c 100644
--- a/libstdc++-v3/include/bits/locale_classes.tcc
+++ b/libstdc++-v3/include/bits/locale_classes.tcc
@@ -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
{
--
2.46.0