[libcxx-commits] [libcxx] [libc++][type_traits] `reference_{constructs|converts}_from_temporary` with `-Winvalid-specialization` tests (PR #133946)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 2 01:58:42 PDT 2025
https://github.com/Zingam updated https://github.com/llvm/llvm-project/pull/133946
>From 8fa0026e4d9b0981c1b180e7c50551d68967c3aa Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 1 Apr 2025 20:29:22 +0300
Subject: [PATCH 1/2] [libc++][type_traits]
`reference_{constructs|converts}_from_temporary` `-Winvalid-specialization`
tests
Addresses comment:
https://github.com/llvm/llvm-project/pull/128649/files#r2022341035
Drive-by fix: libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
https://clang.llvm.org/docs/DiagnosticsReference.html#winvalid-specialization
---
.../specialization.verify.cpp | 2 +-
...rence_constructs_from_temporary.verify.cpp | 46 +++++++++++++++++++
...ference_converts_from_temporary.verify.cpp | 46 +++++++++++++++++++
3 files changed, 93 insertions(+), 1 deletion(-)
create mode 100644 libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp
create mode 100644 libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp
diff --git a/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp b/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
index 11807059c71b0..54b2f6db41c7e 100644
--- a/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
+++ b/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
@@ -15,7 +15,7 @@
#include <initializer_list>
-#if !__has_warning("-Winvalid-specializations")
+#if !__has_warning("-Winvalid-specialization")
// expected-no-diagnostics
#else
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp
new file mode 100644
index 0000000000000..5607efec49ea9
--- /dev/null
+++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++23
+
+// These compilers don't support std::reference_converts_from_temporary yet.
+// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-19.1
+
+// <type_traits>
+
+// template<class T, class U> struct reference_constructs_from_temporary;
+
+// template<class T, class U>
+// constexpr bool reference_constructs_from_temporary_v
+// = reference_constructs_from_temporary<T, U>::value;
+
+#include <type_traits>
+
+#if !__has_warning("-Winvalid-specialization")
+// expected-no-diagnostics
+#else
+
+// expected-error at +2 {{'reference_constructs_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <>
+struct std::reference_constructs_from_temporary<int, int> {
+}; //expected-error 0-1 {{explicit specialization of 'std::reference_constructs_from_temporary<int, int>' after instantiation}}
+
+// expected-error at +2 {{'reference_constructs_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <typename T, typename U>
+struct std::reference_constructs_from_temporary<T&, U&> {};
+
+// expected-error at +2 {{'reference_constructs_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <>
+inline constexpr bool std::reference_constructs_from_temporary_v<int, int> =
+ false; // expected-error 0-1 {{explicit specialization of 'std::reference_constructs_from_temporary_v<int, int>' after instantiation}}
+
+// expected-error at +2 {{'reference_constructs_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <class T, class U>
+inline constexpr bool std::reference_constructs_from_temporary_v<T&, U&> = false;
+
+#endif
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp
new file mode 100644
index 0000000000000..607479f76f46d
--- /dev/null
+++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++23
+
+// These compilers don't support std::reference_converts_from_temporary yet.
+// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-18, clang-19.1
+
+// <type_traits>
+
+// template<class T, class U> struct reference_converts_from_temporary;
+
+// template<class T, class U>
+// constexpr bool reference_converts_from_temporary_v
+// = reference_converts_from_temporary<T, U>::value;
+
+#include <type_traits>
+
+#if !__has_warning("-Winvalid-specialization")
+// expected-no-diagnostics
+#else
+
+// expected-error at +2 {{'reference_converts_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <>
+struct std::reference_converts_from_temporary<int, int> {
+}; //expected-error 0-1 {{explicit specialization of 'std::reference_converts_from_temporary<int, int>' after instantiation}}
+
+// expected-error at +2 {{'reference_converts_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <typename T, typename U>
+struct std::reference_converts_from_temporary<T&, U&> {};
+
+// expected-error at +2 {{'reference_converts_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <>
+inline constexpr bool std::reference_converts_from_temporary_v<int, int> =
+ false; // expected-error 0-1 {{explicit specialization of 'std::reference_converts_from_temporary_v<int, int>' after instantiation}}
+
+// expected-error at +2 {{'reference_converts_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <class T, class U>
+inline constexpr bool std::reference_converts_from_temporary_v<T&, U&> = false;
+
+#endif
>From fe47391499b8b5de7a41cda8cd770c8aeba5e370 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 2 Apr 2025 11:57:09 +0300
Subject: [PATCH 2/2] Addressed review comments
---
.../type_traits/no_specializations.verify.cpp | 10 +++-
...rence_constructs_from_temporary.verify.cpp | 46 -------------------
...ference_converts_from_temporary.verify.cpp | 46 -------------------
3 files changed, 8 insertions(+), 94 deletions(-)
delete mode 100644 libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp
delete mode 100644 libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp
diff --git a/libcxx/test/libcxx/type_traits/no_specializations.verify.cpp b/libcxx/test/libcxx/type_traits/no_specializations.verify.cpp
index 807d01e381b49..38560161f162e 100644
--- a/libcxx/test/libcxx/type_traits/no_specializations.verify.cpp
+++ b/libcxx/test/libcxx/type_traits/no_specializations.verify.cpp
@@ -156,6 +156,12 @@ SPECIALIZE_UTT(is_unbounded_array); // expected-error 2 {{cannot be speciali
# if TEST_STD_VER >= 23
SPECIALIZE_UTT(is_implicit_lifetime); // expected-error 2 {{cannot be specialized}}
SPECIALIZE_UTT(is_scoped_enum); // expected-error 2 {{cannot be specialized}}
+# if __has_builtin(__reference_constructs_from_temporary)
+SPECIALIZE_BTT(reference_constructs_from_temporary); // expected-error 2 {{cannot be specialized}}
+# endif
+# if __has_builtin(__reference_converts_from_temporary)
+SPECIALIZE_BTT(reference_converts_from_temporary); // expected-error 2 {{cannot be specialized}}
+# endif
# endif
# if TEST_STD_VER >= 26
@@ -177,8 +183,8 @@ struct std::conditional<true, S, S>; // expected-error {{cannot be specialized}}
template <>
struct std::enable_if<true, S>; // expected-error {{cannot be specialized}}
-#if TEST_STD_VER >= 20
+# if TEST_STD_VER >= 20
template <>
struct std::integral_constant<S, {}>; // expected-error {{cannot be specialized}}
-#endif
+# endif
#endif
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp
deleted file mode 100644
index 5607efec49ea9..0000000000000
--- a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.verify.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: std-at-least-c++23
-
-// These compilers don't support std::reference_converts_from_temporary yet.
-// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-19.1
-
-// <type_traits>
-
-// template<class T, class U> struct reference_constructs_from_temporary;
-
-// template<class T, class U>
-// constexpr bool reference_constructs_from_temporary_v
-// = reference_constructs_from_temporary<T, U>::value;
-
-#include <type_traits>
-
-#if !__has_warning("-Winvalid-specialization")
-// expected-no-diagnostics
-#else
-
-// expected-error at +2 {{'reference_constructs_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <>
-struct std::reference_constructs_from_temporary<int, int> {
-}; //expected-error 0-1 {{explicit specialization of 'std::reference_constructs_from_temporary<int, int>' after instantiation}}
-
-// expected-error at +2 {{'reference_constructs_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <typename T, typename U>
-struct std::reference_constructs_from_temporary<T&, U&> {};
-
-// expected-error at +2 {{'reference_constructs_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <>
-inline constexpr bool std::reference_constructs_from_temporary_v<int, int> =
- false; // expected-error 0-1 {{explicit specialization of 'std::reference_constructs_from_temporary_v<int, int>' after instantiation}}
-
-// expected-error at +2 {{'reference_constructs_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <class T, class U>
-inline constexpr bool std::reference_constructs_from_temporary_v<T&, U&> = false;
-
-#endif
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp
deleted file mode 100644
index 607479f76f46d..0000000000000
--- a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.verify.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: std-at-least-c++23
-
-// These compilers don't support std::reference_converts_from_temporary yet.
-// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-18, clang-19.1
-
-// <type_traits>
-
-// template<class T, class U> struct reference_converts_from_temporary;
-
-// template<class T, class U>
-// constexpr bool reference_converts_from_temporary_v
-// = reference_converts_from_temporary<T, U>::value;
-
-#include <type_traits>
-
-#if !__has_warning("-Winvalid-specialization")
-// expected-no-diagnostics
-#else
-
-// expected-error at +2 {{'reference_converts_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <>
-struct std::reference_converts_from_temporary<int, int> {
-}; //expected-error 0-1 {{explicit specialization of 'std::reference_converts_from_temporary<int, int>' after instantiation}}
-
-// expected-error at +2 {{'reference_converts_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <typename T, typename U>
-struct std::reference_converts_from_temporary<T&, U&> {};
-
-// expected-error at +2 {{'reference_converts_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <>
-inline constexpr bool std::reference_converts_from_temporary_v<int, int> =
- false; // expected-error 0-1 {{explicit specialization of 'std::reference_converts_from_temporary_v<int, int>' after instantiation}}
-
-// expected-error at +2 {{'reference_converts_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
-template <class T, class U>
-inline constexpr bool std::reference_converts_from_temporary_v<T&, U&> = false;
-
-#endif
More information about the libcxx-commits
mailing list