Skip to content

Commit 8fa0026

Browse files
committed
[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
1 parent 105c8c3 commit 8fa0026

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include <initializer_list>
1717

18-
#if !__has_warning("-Winvalid-specializations")
18+
#if !__has_warning("-Winvalid-specialization")
1919
// expected-no-diagnostics
2020
#else
2121

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++23
10+
11+
// These compilers don't support std::reference_converts_from_temporary yet.
12+
// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-19.1
13+
14+
// <type_traits>
15+
16+
// template<class T, class U> struct reference_constructs_from_temporary;
17+
18+
// template<class T, class U>
19+
// constexpr bool reference_constructs_from_temporary_v
20+
// = reference_constructs_from_temporary<T, U>::value;
21+
22+
#include <type_traits>
23+
24+
#if !__has_warning("-Winvalid-specialization")
25+
// expected-no-diagnostics
26+
#else
27+
28+
// expected-error@+2 {{'reference_constructs_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
29+
template <>
30+
struct std::reference_constructs_from_temporary<int, int> {
31+
}; //expected-error 0-1 {{explicit specialization of 'std::reference_constructs_from_temporary<int, int>' after instantiation}}
32+
33+
// expected-error@+2 {{'reference_constructs_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
34+
template <typename T, typename U>
35+
struct std::reference_constructs_from_temporary<T&, U&> {};
36+
37+
// expected-error@+2 {{'reference_constructs_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
38+
template <>
39+
inline constexpr bool std::reference_constructs_from_temporary_v<int, int> =
40+
false; // expected-error 0-1 {{explicit specialization of 'std::reference_constructs_from_temporary_v<int, int>' after instantiation}}
41+
42+
// expected-error@+2 {{'reference_constructs_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
43+
template <class T, class U>
44+
inline constexpr bool std::reference_constructs_from_temporary_v<T&, U&> = false;
45+
46+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++23
10+
11+
// These compilers don't support std::reference_converts_from_temporary yet.
12+
// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-18, clang-19.1
13+
14+
// <type_traits>
15+
16+
// template<class T, class U> struct reference_converts_from_temporary;
17+
18+
// template<class T, class U>
19+
// constexpr bool reference_converts_from_temporary_v
20+
// = reference_converts_from_temporary<T, U>::value;
21+
22+
#include <type_traits>
23+
24+
#if !__has_warning("-Winvalid-specialization")
25+
// expected-no-diagnostics
26+
#else
27+
28+
// expected-error@+2 {{'reference_converts_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
29+
template <>
30+
struct std::reference_converts_from_temporary<int, int> {
31+
}; //expected-error 0-1 {{explicit specialization of 'std::reference_converts_from_temporary<int, int>' after instantiation}}
32+
33+
// expected-error@+2 {{'reference_converts_from_temporary' cannot be specialized: Users are not allowed to specialize this standard library entity}}
34+
template <typename T, typename U>
35+
struct std::reference_converts_from_temporary<T&, U&> {};
36+
37+
// expected-error@+2 {{'reference_converts_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
38+
template <>
39+
inline constexpr bool std::reference_converts_from_temporary_v<int, int> =
40+
false; // expected-error 0-1 {{explicit specialization of 'std::reference_converts_from_temporary_v<int, int>' after instantiation}}
41+
42+
// expected-error@+2 {{'reference_converts_from_temporary_v' cannot be specialized: Users are not allowed to specialize this standard library entity}}
43+
template <class T, class U>
44+
inline constexpr bool std::reference_converts_from_temporary_v<T&, U&> = false;
45+
46+
#endif

0 commit comments

Comments
 (0)