| 1 |
// RUN: %clang_cc1 -std=c++2c -verify %s |
| 2 |
|
| 3 |
namespace Errors { |
| 4 |
|
| 5 |
template <template<typename T> auto> |
| 6 |
struct S1; |
| 7 |
template <template<auto T> auto> |
| 8 |
struct S2; |
| 9 |
template <template<typename T> concept> |
| 10 |
struct S3; |
| 11 |
template <template<auto T> concept> |
| 12 |
struct S4; |
| 13 |
int a; |
| 14 |
|
| 15 |
template <typename T> |
| 16 |
concept C = true; // expected-note 2{{template argument refers to a concept 'C', here}} |
| 17 |
template <typename T> |
| 18 |
auto Var = 0; // expected-note 2{{template argument refers to a variable template 'Var', here}} |
| 19 |
|
| 20 |
S1<1> t1; // expected-error {{template argument for template template parameter must be a variable template}} |
| 21 |
S1<a> t2; // expected-error {{template argument for template template parameter must be a variable template}} |
| 22 |
S1<int> t3; // expected-error {{template argument for template template parameter must be a variable template}} |
| 23 |
S1<C> t4; // expected-error {{template argument does not refer to a variable template, or template template parameter}} |
| 24 |
S2<1> t5; // expected-error {{template argument for template template parameter must be a variable template}} |
| 25 |
S2<a> t6; // expected-error {{template argument for template template parameter must be a variable template}} |
| 26 |
S2<int> t7; // expected-error {{template argument for template template parameter must be a variable template}} |
| 27 |
S2<C> t8; // expected-error {{template argument does not refer to a variable template, or template template parameter}} |
| 28 |
S3<1> t9; // expected-error {{template argument for template template parameter must be a concept}} |
| 29 |
S3<a> t10; // expected-error {{template argument for template template parameter must be a concept}} |
| 30 |
S3<int> t11; // expected-error {{template argument for template template parameter must be a concept}} |
| 31 |
S3<Var> t12; // expected-error {{template argument does not refer to a concept, or template template parameter}} |
| 32 |
S4<1> t13; // expected-error {{template argument for template template parameter must be a concept}} |
| 33 |
S4<a> t14; // expected-error {{template argument for template template parameter must be a concept}} |
| 34 |
S4<int> t15; // expected-error {{template argument for template template parameter must be a concept}} |
| 35 |
S4<Var> t16; // expected-error {{template argument does not refer to a concept, or template template parameter}} |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
template <template<typename T> auto V> // expected-note {{previous template template parameter is here}} \ |
| 40 |
// expected-error{{template argument for non-type template parameter must be an expression}} |
| 41 |
struct S1 { |
| 42 |
static_assert(V<int> == 42); |
| 43 |
static_assert(V<const int> == 84); |
| 44 |
static_assert(V<double> == 0); |
| 45 |
}; |
| 46 |
template <template<auto T> auto V> // expected-error {{template argument for template type parameter must be a type}} \ |
| 47 |
// expected-note {{previous template template parameter is here}} |
| 48 |
struct S2 { |
| 49 |
static_assert(V<0> == 1); |
| 50 |
static_assert(V<1> == 0); |
| 51 |
}; |
| 52 |
template <template<typename T> concept C > // expected-error {{template argument for non-type template parameter must be an expression}} \ |
| 53 |
// expected-note {{previous template template parameter is here}} |
| 54 |
struct S3 { |
| 55 |
static_assert(C<int>); |
| 56 |
}; |
| 57 |
template <template<auto> concept C> // expected-error {{template argument for template type parameter must be a type}} \ |
| 58 |
// expected-note {{previous template template parameter is here}} |
| 59 |
struct S4 { |
| 60 |
static_assert(C<0>); |
| 61 |
}; |
| 62 |
|
| 63 |
template <typename T> // expected-note {{template parameter is declared here}} |
| 64 |
concept C = true; |
| 65 |
|
| 66 |
template <auto I> // expected-note {{template parameter is declared here}} |
| 67 |
concept CI = true; |
| 68 |
|
| 69 |
template <typename T> // expected-note {{template parameter is declared here}} |
| 70 |
constexpr auto Var = 42; |
| 71 |
template <typename T> |
| 72 |
constexpr auto Var<const T> = 84; |
| 73 |
template <> |
| 74 |
constexpr auto Var<double> = 0; |
| 75 |
|
| 76 |
template <auto N> // expected-note {{template parameter is declared here}} |
| 77 |
constexpr auto Var2 = 0; |
| 78 |
template <auto N> |
| 79 |
requires (N%2 == 0) |
| 80 |
constexpr auto Var2<N> = 1; |
| 81 |
|
| 82 |
void test () { |
| 83 |
S1<Var2> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}} |
| 84 |
S2<Var> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}} |
| 85 |
S1<Var> s1; |
| 86 |
S2<Var2> s2; |
| 87 |
S3<C> s3; |
| 88 |
S4<C> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}} |
| 89 |
S4<CI> s4; |
| 90 |
S3<CI> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
namespace template_type_constraints { |
| 95 |
|
| 96 |
|
| 97 |
template <typename T> |
| 98 |
concept Unary = true; |
| 99 |
template <typename T, typename = int> |
| 100 |
concept BinaryDefaulted = true; |
| 101 |
|
| 102 |
template <typename T> |
| 103 |
concept UnaryFalse = false; // expected-note 3{{because 'false' evaluated to false}} |
| 104 |
template <typename T, typename = int> |
| 105 |
concept BinaryDefaultedFalse = false; |
| 106 |
|
| 107 |
template <template <typename...> concept C, typename T> |
| 108 |
struct S { |
| 109 |
template <C TT> // expected-note 2{{because 'int' does not satisfy 'UnaryFalse'}} |
| 110 |
void f(TT); // expected-note {{ignored}} |
| 111 |
void g(C auto); // expected-note {{ignored}} \ |
| 112 |
// expected-note {{because 'int' does not satisfy 'UnaryFalse'}} |
| 113 |
|
| 114 |
auto h() -> C auto { // expected-error {{deduced type 'int' does not satisfy 'UnaryFalse'}} |
| 115 |
return 0; |
| 116 |
}; |
| 117 |
|
| 118 |
void test() { |
| 119 |
C auto a = 0; |
| 120 |
} |
| 121 |
}; |
| 122 |
|
| 123 |
template <template <typename...> concept C, typename T> |
| 124 |
struct SArg { |
| 125 |
template <C<int> TT> |
| 126 |
void f(TT); |
| 127 |
void g(C<int> auto); |
| 128 |
|
| 129 |
auto h() -> C<int> auto { |
| 130 |
return 0; |
| 131 |
}; |
| 132 |
void test() { |
| 133 |
C<int> auto a = 0; |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
void test() { |
| 138 |
S<Unary, int> s; |
| 139 |
s.f(0); |
| 140 |
s.g(0); |
| 141 |
s.h(); |
| 142 |
S<BinaryDefaulted, int> s2; |
| 143 |
s2.f(0); |
| 144 |
s2.g(0); |
| 145 |
s2.h(); |
| 146 |
|
| 147 |
SArg<BinaryDefaulted, int> s3; |
| 148 |
s3.f(0); |
| 149 |
s3.g(0); |
| 150 |
s3.h(); |
| 151 |
} |
| 152 |
|
| 153 |
void test_errors() { |
| 154 |
S<UnaryFalse, int> s; |
| 155 |
s.f(0); // expected-error {{no matching member function for call to 'f'}} |
| 156 |
s.g(0); // expected-error {{no matching member function for call to 'g'}} |
| 157 |
s.h(); // expected-note {{in instantiation of member function 'template_type_constraints::S<template_type_constraints::UnaryFalse, int>::h'}} |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
template <typename T> |
| 163 |
concept Unary = true; |
| 164 |
template <typename T, typename = int> |
| 165 |
concept BinaryDefaulted = true; |
| 166 |
|
| 167 |
template <typename T> |
| 168 |
concept UnaryFalse = false; // expected-note 3{{because 'false' evaluated to false}} |
| 169 |
template <typename T, typename = int> |
| 170 |
concept BinaryDefaultedFalse = false; |
| 171 |
|
| 172 |
template <template <typename...> concept C, typename T> |
| 173 |
struct S { |
| 174 |
template <C TT> // expected-note 2{{because 'int' does not satisfy 'UnaryFalse'}} |
| 175 |
void f(TT); // expected-note {{ignored}} |
| 176 |
void g(C auto); // expected-note {{ignored}} \ |
| 177 |
// expected-note {{because 'int' does not satisfy 'UnaryFalse'}} |
| 178 |
|
| 179 |
auto h() -> C auto { // expected-error {{deduced type 'int' does not satisfy 'UnaryFalse'}} |
| 180 |
return 0; |
| 181 |
}; |
| 182 |
|
| 183 |
void test() { |
| 184 |
C auto a = 0; |
| 185 |
} |
| 186 |
}; |
| 187 |
|
| 188 |
template <template <typename...> concept C, typename T> |
| 189 |
struct SArg { |
| 190 |
template <C<int> TT> |
| 191 |
void f(TT); |
| 192 |
void g(C<int> auto); |
| 193 |
|
| 194 |
auto h() -> C<int> auto { |
| 195 |
return 0; |
| 196 |
}; |
| 197 |
void test() { |
| 198 |
C<int> auto a = 0; |
| 199 |
} |
| 200 |
}; |
| 201 |
|
| 202 |
void test_args() { |
| 203 |
S<Unary, int> s; |
| 204 |
s.f(0); |
| 205 |
s.g(0); |
| 206 |
s.h(); |
| 207 |
S<BinaryDefaulted, int> s2; |
| 208 |
s2.f(0); |
| 209 |
s2.g(0); |
| 210 |
s2.h(); |
| 211 |
|
| 212 |
SArg<BinaryDefaulted, int> s3; |
| 213 |
s3.f(0); |
| 214 |
s3.g(0); |
| 215 |
s3.h(); |
| 216 |
} |
| 217 |
|
| 218 |
void test_errors() { |
| 219 |
S<UnaryFalse, int> s; |
| 220 |
s.f(0); // expected-error {{no matching member function for call to 'f'}} |
| 221 |
s.g(0); // expected-error {{no matching member function for call to 'g'}} |
| 222 |
s.h(); // expected-note {{in instantiation of member function 'S<UnaryFalse, int>::h'}} |
| 223 |
} |
| 224 |
|
| 225 |
namespace non_type { |
| 226 |
|
| 227 |
template <auto> |
| 228 |
concept Unary = true; |
| 229 |
|
| 230 |
template <template <auto> concept C> |
| 231 |
struct S { |
| 232 |
template <C Foo> // expected-error {{concept named in type constraint is not a type concept}} |
| 233 |
void f(); |
| 234 |
// FIXME, bad diagnostic |
| 235 |
void g(C auto); // expected-error{{concept named in type constraint is not a type concept}} |
| 236 |
auto h() -> C auto { // expected-error{{concept named in type constraint is not a type concept}} |
| 237 |
} |
| 238 |
void i() { |
| 239 |
C auto a = 0; // expected-error{{concept named in type constraint is not a type concept}} |
| 240 |
} |
| 241 |
}; |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
namespace default_args { |
| 246 |
|
| 247 |
template <typename T> |
| 248 |
concept Concept = false; // expected-note 2{{template argument refers to a concept 'Concept', here}} \ |
| 249 |
// expected-note 2{{because 'false' evaluated to false}} |
| 250 |
|
| 251 |
template <typename T> |
| 252 |
constexpr auto Var = false; // expected-note 2{{template argument refers to a variable template 'Var', here}} |
| 253 |
|
| 254 |
template <typename T> |
| 255 |
struct Type; // expected-note 2{{template argument refers to a class template 'Type', here}} |
| 256 |
|
| 257 |
|
| 258 |
template <template <typename> auto = Concept> // expected-error {{template argument does not refer to a variable template, or template template parameter}} |
| 259 |
struct E1; |
| 260 |
|
| 261 |
template <template <typename> auto = Type> // expected-error {{template argument does not refer to a variable template, or template template parameter}} |
| 262 |
struct E2; |
| 263 |
|
| 264 |
template <template <typename> typename = Concept> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}} |
| 265 |
struct E3; |
| 266 |
|
| 267 |
template <template <typename> typename = Var> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}} |
| 268 |
struct E4; |
| 269 |
|
| 270 |
template <template <typename> concept = Var> // expected-error {{template argument does not refer to a concept, or template template parameter}} |
| 271 |
struct E4; |
| 272 |
|
| 273 |
template <template <typename> concept = Type> // expected-error {{template argument does not refer to a concept, or template template parameter}} |
| 274 |
struct E4; |
| 275 |
|
| 276 |
template < |
| 277 |
template <typename> concept TConcept, // expected-note 2{{template argument refers to a concept 'TConcept', here}} |
| 278 |
template <typename> auto TVar, // expected-note 2{{template argument refers to a variable template 'TVar', here}} |
| 279 |
template <typename> typename TType // expected-note 2{{template argument refers to a class template 'TType', here}} |
| 280 |
> |
| 281 |
struct Nested { |
| 282 |
template <template <typename> auto = TConcept> // expected-error {{template argument does not refer to a variable template, or template template parameter}} |
| 283 |
struct E1; |
| 284 |
|
| 285 |
template <template <typename> auto = TType> // expected-error {{template argument does not refer to a variable template, or template template parameter}} |
| 286 |
struct E2; |
| 287 |
|
| 288 |
template <template <typename> typename = TConcept> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}} |
| 289 |
struct E3; |
| 290 |
|
| 291 |
template <template <typename> typename = TVar> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}} |
| 292 |
struct E4; |
| 293 |
|
| 294 |
template <template <typename> concept = TVar> // expected-error {{template argument does not refer to a concept, or template template parameter}} |
| 295 |
struct E4; |
| 296 |
|
| 297 |
template <template <typename> concept = TType> // expected-error {{template argument does not refer to a concept, or template template parameter}} |
| 298 |
struct E4; |
| 299 |
}; |
| 300 |
|
| 301 |
|
| 302 |
template <template <typename> concept C = Concept> |
| 303 |
struct TestDefaultConcept { |
| 304 |
template <template <typename> concept CC = C> |
| 305 |
void f() { |
| 306 |
static_assert(C<int>); // expected-error {{static assertion failed}} \ |
| 307 |
// expected-note {{because 'int' does not satisfy 'Concept'}} |
| 308 |
static_assert(CC<int>); // expected-error {{static assertion failed}} \ |
| 309 |
// expected-note {{because 'int' does not satisfy 'Concept'}} |
| 310 |
} |
| 311 |
}; |
| 312 |
void do_test_concept() { |
| 313 |
TestDefaultConcept<>{}.f(); // expected-note {{in instantiation}} |
| 314 |
} |
| 315 |
|
| 316 |
template <template <typename> auto V = Var> |
| 317 |
struct TestDefaultVar { |
| 318 |
template <template <typename> auto VV = V> |
| 319 |
void f() { |
| 320 |
static_assert(V<int>); // expected-error {{static assertion failed}} |
| 321 |
static_assert(VV<int>); // expected-error {{static assertion failed}} |
| 322 |
} |
| 323 |
}; |
| 324 |
void do_test_var() { |
| 325 |
TestDefaultVar<>{}.f(); // expected-note {{in instantiation}} |
| 326 |
} |
| 327 |
|
| 328 |
} |
| 329 |
|
| 330 |
namespace TTPDependence { |
| 331 |
template <template <typename... > concept C> |
| 332 |
concept A = C<>; |
| 333 |
template <template <typename... > concept C> |
| 334 |
concept B = C<int>; |
| 335 |
|
| 336 |
template <template <typename... > auto Var> |
| 337 |
concept C = Var<>; |
| 338 |
template <template <typename... > auto Var> |
| 339 |
concept D = Var<int>; |
| 340 |
|
| 341 |
} |
| 342 |
|
| 343 |
namespace InvalidName { |
| 344 |
template <typename T, template <typename> concept C> |
| 345 |
concept A = C<T>; // expected-note {{here}} |
| 346 |
|
| 347 |
template <A<concept missing<int>> T> // expected-error {{expected expression}} \ |
| 348 |
// expected-error {{too few template arguments for concept 'A'}} \ |
| 349 |
// expected-error {{unknown type name 'T'}} \ |
| 350 |
// expected-error {{expected unqualified-id}} |
| 351 |
auto f(); |
| 352 |
} |
| 353 |
|
| 354 |
namespace concept_arg_normalization { |
| 355 |
|
| 356 |
template <typename T, |
| 357 |
template <typename...> concept C1> |
| 358 |
concept one = (C1<T>); // #concept-arg-one |
| 359 |
|
| 360 |
template <typename T> |
| 361 |
concept A = true; // #concept-arg-A |
| 362 |
|
| 363 |
template <typename T> |
| 364 |
concept BetterA = A<T> && true; |
| 365 |
|
| 366 |
template <typename T> |
| 367 |
concept B = true; // #concept-arg-B |
| 368 |
|
| 369 |
template <typename T> |
| 370 |
concept False = false; // #concept-arg-False |
| 371 |
|
| 372 |
template <typename T> |
| 373 |
requires one<T, A> |
| 374 |
void f1(T){} // #concept-arg-f1-1 |
| 375 |
|
| 376 |
template <typename T> |
| 377 |
requires one<T, B> |
| 378 |
void f1(T){} // #concept-arg-f1-2 |
| 379 |
|
| 380 |
template <typename T> |
| 381 |
requires one<T, A> |
| 382 |
void f2(T){} |
| 383 |
|
| 384 |
template <typename T> |
| 385 |
requires one<T, BetterA> |
| 386 |
void f2(T){} |
| 387 |
|
| 388 |
|
| 389 |
template <template <typename> concept CT> |
| 390 |
requires one<int, A> |
| 391 |
void f3(){} // #concept-arg-f3-1 |
| 392 |
|
| 393 |
template <template <typename> concept CT> |
| 394 |
requires one<int, CT> |
| 395 |
void f3(){} // #concept-arg-f3-2 |
| 396 |
|
| 397 |
template <typename T> |
| 398 |
requires one<T, False> void f4(T){} // #concept-arg-f4 |
| 399 |
|
| 400 |
|
| 401 |
void test() { |
| 402 |
f1(0); |
| 403 |
// expected-error@-1 {{call to 'f1' is ambiguous}} |
| 404 |
// expected-note@#concept-arg-f1-1{{candidate function [with T = int]}} |
| 405 |
// expected-note@#concept-arg-f1-2{{candidate function [with T = int]}} |
| 406 |
// expected-note@#concept-arg-A {{similar constraint expressions not considered equivalent}} |
| 407 |
// expected-note@#concept-arg-B {{similar constraint expression here}} |
| 408 |
f2(0); |
| 409 |
|
| 410 |
f3<BetterA>(); |
| 411 |
// expected-error@-1 {{call to 'f3' is ambiguous}} |
| 412 |
// expected-note@#concept-arg-f3-1 {{candidate function [with CT = concept_arg_normalization::BetterA]}} |
| 413 |
// expected-note@#concept-arg-f3-2 {{candidate function [with CT = concept_arg_normalization::BetterA]}} |
| 414 |
|
| 415 |
static_assert(one<int, A>); |
| 416 |
static_assert(one<int, False>); |
| 417 |
// expected-error@-1 {{static assertion failed}} \ |
| 418 |
// expected-note@-1 {{because 'one<int, False>' evaluated to false}} |
| 419 |
// expected-note@#concept-arg-one {{because 'int' does not satisfy 'False'}} |
| 420 |
// expected-note@#concept-arg-False {{because 'false' evaluated to false}} |
| 421 |
|
| 422 |
f4(0); |
| 423 |
// expected-error@-1 {{no matching function for call to 'f4'}} |
| 424 |
// expected-note@#concept-arg-f4 {{candidate template ignored: constraints not satisfied [with T = int]}} |
| 425 |
// expected-note@#concept-arg-f4 {{because 'one<int, False>'}} |
| 426 |
// expected-note@#concept-arg-one {{because 'int' does not satisfy 'False'}} |
| 427 |
// expected-note@#concept-arg-False {{because 'false' evaluated to false}} |
| 428 |
|
| 429 |
} |
| 430 |
|
| 431 |
template <typename T, template <typename...> concept C1> |
| 432 |
concept TestBinary = T::a || C1<T>; |
| 433 |
static_assert(TestBinary<int, A>); |
| 434 |
|
| 435 |
|
| 436 |
} |