// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify // Test parsing of the optional requires-clause in a template-declaration. template requires true void foo() { } template requires (!0) struct A { void foo(); struct AA; enum E : int; static int x; template requires true void Mfoo(); template requires true struct M; template requires true static int Mx; template requires true using MQ = M; }; template requires (!0) void A::foo() { } template requires (!0) struct A::AA { }; template requires (!0) enum A::E : int { E0 }; template requires (!0) int A::x = 0; template requires (!0) template requires true void A::Mfoo() { } template requires (!0) template requires true struct A::M { }; template requires (!0) template requires true int A::Mx = 0; template requires true int x = 0; template requires true using Q = A; struct C { template requires true void Mfoo(); template requires true struct M; template requires true static int Mx; template requires true using MQ = M; }; template requires true void C::Mfoo() { } template requires true struct C::M { }; template requires true int C::Mx = 0; // Test behavior with non-primary-expression requires clauses template requires foo() // expected-error@-1{{parentheses are required around this expression in a requires clause}} struct B1 { }; int func() { } template requires func() // expected-error@-1{{atomic constraint must be of type 'bool' (found '')}} // expected-note@-2{{parentheses are required around this expression in a requires clause}} struct B2 { }; template requires (foo()) struct B3 { }; template requires T{} // expected-error@-1{{parentheses are required around this expression in a requires clause}} struct B4 { }; template requires sizeof(T) == 0 // expected-error@-1{{parentheses are required around this expression in a requires clause}} struct B5 { }; template requires (sizeof(T)) == 0 // expected-error@-1{{parentheses are required around this expression in a requires clause}} struct B6 { }; template requires 0 // expected-error@-1{{atomic constraint must be of type 'bool' (found 'int')}} (int) bar() { }; template requires foo (int) bar() { }; // expected-error@-1{{expected '(' for function-style cast or type construction}} template void bar() requires foo(); // expected-error@-1{{parentheses are required around this expression in a requires clause}} template void bar() requires (foo()); template void bar() requires func(); // expected-error@-1{{atomic constraint must be of type 'bool' (found '')}} // expected-note@-2{{parentheses are required around this expression in a requires clause}} template void bar() requires T{}; // expected-error@-1{{parentheses are required around this expression in a requires clause}} template void bar() requires sizeof(T) == 0; // expected-error@-1{{parentheses are required around this expression in a requires clause}} template void bar() requires (sizeof(T)) == 0; // expected-error@-1{{parentheses are required around this expression in a requires clause}} void bar(int x, int y) requires (x, y, true); struct B { int x; void foo(int y) requires (x, this, this->x, y, true); static void bar(int y) requires (x, true); // expected-error@-1{{'this' cannot be implicitly used in a static member function declaration}} static void baz(int y) requires (this, true); // expected-error@-1{{'this' cannot be used in a static member function declaration}} }; auto lambda1 = [] (auto x) requires (sizeof(decltype(x)) == 1) { }; auto lambda2 = [] (auto x) constexpr -> int requires (sizeof(decltype(x)) == 1) { return 0; }; auto lambda3 = [] requires (sizeof(char) == 1) { }; // expected-error@-1{{lambda requires '()' before 'requires' clause}}