Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / dcl / dcl.decl / p3.cpp
blobf141568ba6c2217bbdd112300ab5f882cf324eaa
1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 template<typename T, typename U>
4 constexpr bool is_same_v = false;
6 template<typename T>
7 constexpr bool is_same_v<T, T> = true;
9 using T = void ();
11 void f1non_templ(int a) requires true; // expected-error{{non-templated function cannot have a requires clause}}
12 auto f2non_templ(int a) -> bool requires true; // expected-error{{non-templated function cannot have a requires clause}}
13 auto f3non_templ(int a) -> bool (*)(int b) requires true; // expected-error{{non-templated function cannot have a requires clause}}
14 // expected-error@+1{{non-templated function cannot have a requires clause}}
15 auto f4_non_templ(int a) requires true -> bool; // expected-error{{trailing return type must appear before trailing requires clause}}
16 void (f7non_templ()) requires true; // expected-error{{non-templated function cannot have a requires clause}}
17 // expected-error@+1{{non-templated function cannot have a requires clause}}
18 void (f8non_templ() requires true); // expected-error{{trailing requires clause should be placed outside parentheses}}
19 // expected-error@+1{{non-templated function cannot have a requires clause}}
20 T xnon_templ requires true;
21 // expected-error@+2 2{{non-templated function cannot have a requires clause}}
22 struct Snon_templ {
23 T m1 requires true, m2 requires true;
26 template <typename>
27 void f1(int a)
28 requires true; // OK
30 template <typename>
31 auto f2(int a) -> bool
32 requires true; // OK
34 template <typename>
35 auto f3(int a) -> bool (*)(int b) requires true; // OK
36 template <typename>
37 auto f4(int a) requires true -> bool; // expected-error{{trailing return type must appear before trailing requires clause}}
38 int f5(int a) requires; // expected-error{{expected expression}}
39 int f6(int a) requires {} // expected-error{{expected expression}}
40 template<typename>
41 void (f7()) requires true;
42 template<typename>
43 void (f8() requires true); // expected-error{{trailing requires clause should be placed outside parentheses}}
44 void (*(f9 requires (true)))(); // expected-error{{trailing requires clause should be placed outside parentheses}}
45 static_assert(is_same_v<decltype(f9), void (*)()>);
46 void (*pf)() requires true; // expected-error{{trailing requires clause can only be used when declaring a function}}
47 void g1(int (*dsdads)() requires false); // expected-error{{trailing requires clause can only be used when declaring a function}}
48 void g2(int (*(*dsdads)())() requires true); // expected-error{{trailing requires clause can only be used when declaring a function}}
49 void g3(int (*(*dsdads)(int) requires true)() ); // expected-error{{trailing requires clause should be placed outside parentheses}}
51 template<typename U>
52 struct Foo{
53 T x requires true;
55 Foo<int> f;
57 template<typename>
58 struct S {
59 T m1 requires true, m2 requires true;
62 template<typename T>
63 struct R {
64 R(T t);
67 template<typename T>
68 R(T) -> R<T> requires true; // expected-error{{deduction guide cannot have a requires clause}}