1 // RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
3 template<typename T
, typename U
> constexpr bool is_same_v
= false;
4 template<typename T
> constexpr bool is_same_v
<T
, T
> = true;
6 template<typename T
> struct identity
{ using type
= T
; };
7 template<typename T
> using identity_t
= T
;
10 template<typename T
> requires requires
{ typename identity_t
<T
>; }
12 template<typename U
> requires requires
{ typename identity_t
<U
>; } // expected-note{{previous template declaration is here}}
14 template<typename T
> requires requires
{ typename identity_t
<T
*>; } // expected-error{{requires clause differs in template redeclaration}}
16 template<typename T
> requires requires
{ typename ::identity_t
<T
>; }
19 template<typename Y
> requires requires
{ typename identity
<Y
>::type
; }
21 template<typename U
> requires requires
{ typename identity
<U
>::type
; }
23 template<typename T
> requires requires
{ typename ::identity
<T
>::type
; } // expected-note 2{{previous template declaration is here}}
25 template<typename T
> requires requires
{ typename identity
<T
>::typr
; } // expected-error{{requires clause differs in template redeclaration}}
28 template<typename T
> struct identity
{ using type
= T
; };
30 template<typename T
> requires requires
{ typename
ns::identity
<T
>::type
; } // expected-error{{requires clause differs in template redeclaration}}
33 template<typename T
> requires requires
{ typename
T::template identity
<T
>::type
; }
35 template<typename U
> requires requires
{ typename
U::template identity
<U
>::type
; } // expected-note{{previous template declaration is here}}
37 template<typename T
> requires requires
{ typename
T::template identitr
<T
>::type
; } // expected-error{{requires clause differs in template redeclaration}}
40 template<typename T
> requires requires
{ typename
T::template temp
<>; }
42 template<typename U
> requires requires
{ typename
U::template temp
<>; }
46 template<typename T
> requires requires
{ 0; } // expected-note{{previous template declaration is here}}
48 template<typename T
> requires requires
{ 1; } // expected-error{{requires clause differs in template redeclaration}}
54 template<typename T
> requires requires
{ sizeof(T
); }
56 template<typename U
> requires requires
{ sizeof(U
); } // expected-note{{previous template declaration is here}}
58 template<typename U
> requires requires
{ sizeof(U
) - 1; } // expected-error{{requires clause differs in template redeclaration}}
60 template<typename T
> requires requires
{ { sizeof(T
) }; } // expected-note 2{{previous template declaration is here}}
62 template<typename T
> requires requires
{ { sizeof(T
) } noexcept
; } // expected-error{{requires clause differs in template redeclaration}}
64 template<typename T
> requires requires
{ { sizeof(T
) } -> C1
; } // expected-error{{requires clause differs in template redeclaration}}
67 template<typename T
> requires requires
{ { sizeof(T
) } -> C1
; }
69 template<typename U
> requires requires
{ { sizeof(U
) } -> C1
; }
71 template<typename T
> requires requires
{ { sizeof(T
) } -> C1
<>; } // expected-note {{previous template declaration is here}}
73 template<typename U
> requires requires
{ { sizeof(U
) }; } // expected-error{{requires clause differs in template redeclaration}}
76 template<typename T
, typename U
>
79 template<typename T
> requires requires
{ { sizeof(T
) } -> C2
<T
>; }
81 template<typename U
> requires requires
{ { sizeof(U
) } -> C2
<U
>; } // expected-note{{previous template declaration is here}}
83 template<typename T
> requires requires
{ { sizeof(T
) } -> C2
<T
*>; } // expected-error{{requires clause differs in template redeclaration}}
86 // Nested requirements
87 template<typename T
> requires requires
{ requires
sizeof(T
) == 0; }
89 template<typename U
> requires requires
{ requires
sizeof(U
) == 0; } // expected-note{{previous template declaration is here}}
91 template<typename T
> requires requires
{ requires
sizeof(T
) == 1; } // expected-error{{requires clause differs in template redeclaration}}
95 template<typename T
> requires requires
{ requires
true; }
97 template<typename T
> requires
requires() { requires
true; } // expected-note{{previous template declaration is here}}
99 template<typename T
> requires
requires(T i
) { requires
true; } // expected-error{{requires clause differs in template redeclaration}}
102 template<typename T
> requires
requires(T i
, T
*j
) { requires
true; } // expected-note 2{{previous template declaration is here}}
104 template<typename T
> requires
requires(T i
) { requires
true; } // expected-error{{requires clause differs in template redeclaration}}
106 template<typename T
> requires
requires(T i
, T
*j
, T
&k
) { requires
true; } // expected-error{{requires clause differs in template redeclaration}}
110 template<typename T
> requires
requires(int i
) { requires
sizeof(i
) == 1; }
112 template<typename T
> requires
requires(int j
) { requires
sizeof(j
) == 1; } // expected-note 2{{previous template declaration is here}}
114 template<typename T
> requires
requires(int k
) { requires
sizeof(k
) == 2; } // expected-error{{requires clause differs in template redeclaration}}
116 template<typename T
> requires
requires(const int k
) { requires
sizeof(k
) == 1; } // expected-error{{requires clause differs in template redeclaration}}
119 // Order of requirements
120 template<typename T
> requires requires
{ requires
true; 0; }
122 template<typename T
> requires requires
{ requires
true; 0; } // expected-note{{previous template declaration is here}}
124 template<typename T
> requires requires
{ 0; requires
true; } // expected-error{{requires clause differs in template redeclaration}}