| 1 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
// expected-error@+2 {{non-templated function cannot have a requires clause}} |
| 4 |
void f1(int a) |
| 5 |
requires true; |
| 6 |
template <typename T> |
| 7 |
auto f2(T a) -> bool |
| 8 |
requires true; // OK |
| 9 |
|
| 10 |
// expected-error@+4 {{trailing return type must appear before trailing requires clause}} |
| 11 |
template <typename T> |
| 12 |
auto f3(T a) |
| 13 |
requires true |
| 14 |
-> bool; |
| 15 |
|
| 16 |
// expected-error@+2{{trailing requires clause can only be used when declaring a function}} |
| 17 |
void (*pf)() |
| 18 |
requires true; |
| 19 |
|
| 20 |
// expected-error@+1{{trailing requires clause can only be used when declaring a function}} |
| 21 |
void g(int (*)() requires true); |
| 22 |
|
| 23 |
// expected-error@+1{{expected expression}} |
| 24 |
auto *p = new void(*)(char) |
| 25 |
requires true; |
| 26 |
|
| 27 |
namespace GH61748 { |
| 28 |
template<typename T> |
| 29 |
struct S { |
| 30 |
// expected-error@+1 {{non-template friend declaration with a requires clause must be a definition}} |
| 31 |
friend void declared_friend() requires(sizeof(T) > 1); |
| 32 |
// OK, is a definition. |
| 33 |
friend void defined_friend() requires(sizeof(T) > 1){} |
| 34 |
// OK, is a member. |
| 35 |
void member() requires(sizeof(T) > 1); |
| 36 |
}; |
| 37 |
|
| 38 |
template<typename T> |
| 39 |
void ContainingFunction() { |
| 40 |
// expected-error@+1 {{non-templated function cannot have a requires clause}} |
| 41 |
void bad() requires(sizeof(T) > 1); |
| 42 |
// expected-error@+1 {{function definition is not allowed here}} |
| 43 |
void still_bad() requires(sizeof(T) > 1) {} |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
void NonTemplContainingFunction() { |
| 48 |
// expected-error@+1 {{non-templated function cannot have a requires clause}} |
| 49 |
(void)[]() requires (sizeof(int)>1){}; |
| 50 |
// OK, a template. |
| 51 |
auto X = [](auto) requires (sizeof(int)>1){}; |
| 52 |
// OK, a template. |
| 53 |
auto Y = []<typename T>(T t) requires (sizeof(int)>1){}; |
| 54 |
|
| 55 |
X(1); |
| 56 |
Y(1); |
| 57 |
} |
| 58 |
|
| 59 |
template<typename T> |
| 60 |
union U { |
| 61 |
void f() requires true; |
| 62 |
}; |
| 63 |
} |