70 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify2 3template<typename T, typename U=void>4concept C = true;5 6namespace ns {7 template<typename T, typename U=void>8 concept D = true;9}10 11int foo() {12 int I;13 {ns::D auto a = 1;}14 {C auto a = 1;}15 {C<> auto a = 1;}16 {C<int> auto a = 1;}17 {ns::D<int> auto a = 1;}18 {const ns::D auto &a = 1;}19 {const C auto &a = 1;}20 {const C<> auto &a = 1;}21 {const C<int> auto &a = 1;}22 {const ns::D<int> auto &a = 1;}23 {C decltype(auto) a = 1;}24 {C<> decltype(auto) a = 1;}25 {C<int> decltype(auto) a = 1;}26 {const C<> decltype(auto) &a = 1;} // expected-error{{'decltype(auto)' cannot be combined with other type specifiers}}27 // expected-error@-1{{cannot form reference to 'decltype(auto)'}}28 {const C<int> decltype(auto) &a = 1;} // expected-error{{'decltype(auto)' cannot be combined with other type specifiers}}29 // expected-error@-1{{cannot form reference to 'decltype(auto)'}}30 {C a = 1;}31 // expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}32 {C const a2 = 1;}33 // expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}34 {C &a3 = I;}35 // expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}36 {C &&a4 = 1;}37 // expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}38 {C decltype a19 = 1;}39 // expected-error@-1{{expected '('}}40 {C decltype(1) a20 = 1;}41 // expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}42}43 44void foo1(C auto &a){}45void foo2(C const &a){}46// expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}47void foo3(C auto const &a){}48void foo4(const C &a){}49// expected-error@-1{{expected 'auto' or 'decltype(auto)' after concept name}}50 51namespace non_type {52 template<int v>53 concept C1 = true;54 55 auto f() -> C1 auto {} // expected-error{{concept named in type constraint is not a type concept}}56 auto g(C1 auto); // expected-error{{concept named in type constraint is not a type concept}}57 C1 auto a = 0; // expected-error{{concept named in type constraint is not a type concept}}58 C1 decltype(auto) b = 0; // expected-error{{concept named in type constraint is not a type concept}}59}60 61namespace arity {62 template<typename v, typename>63 concept C1 = true;64 65 auto f() -> C1 auto {} // expected-error{{'C1' requires more than 1 template argument; provide the remaining arguments explicitly to use it here}}66 auto g(C1 auto); // expected-error{{'C1' requires more than 1 template argument; provide the remaining arguments explicitly to use it here}}67 C1 auto a = 0; // expected-error{{'C1' requires more than 1 template argument; provide the remaining arguments explicitly to use it here}}68 C1 decltype(auto) b = 0; // expected-error{{'C1' requires more than 1 template argument; provide the remaining arguments explicitly to use it here}}69}70