diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1392,12 +1392,6 @@ /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, D, TrailingReturnType, TrailingReturnTypeLoc, &DS), std::move(Attr), DeclEndLoc); - - // Parse requires-clause[opt]. - if (Tok.is(tok::kw_requires)) - ParseTrailingRequiresClause(D); - - WarnIfHasCUDATargetAttr(); }; if (Tok.is(tok::l_paren)) { @@ -1433,6 +1427,12 @@ // Parse lambda-specifiers. ParseLambdaSpecifiers(LParenLoc, /*DeclEndLoc=*/T.getCloseLocation(), ParamInfo, EllipsisLoc); + + // Parse requires-clause[opt]. + if (Tok.is(tok::kw_requires)) + ParseTrailingRequiresClause(D); + + WarnIfHasCUDATargetAttr(); } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute, tok::kw_constexpr, tok::kw_consteval, tok::kw___private, tok::kw___global, tok::kw___local, @@ -1451,6 +1451,8 @@ std::vector EmptyParamInfo; ParseLambdaSpecifiers(/*LParenLoc=*/NoLoc, /*RParenLoc=*/NoLoc, EmptyParamInfo, /*EllipsisLoc=*/NoLoc); + + WarnIfHasCUDATargetAttr(); } // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp b/clang/test/Parser/cxx-concepts-requires-clause.cpp --- a/clang/test/Parser/cxx-concepts-requires-clause.cpp +++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp @@ -154,7 +154,9 @@ auto lambda2 = [] (auto x) constexpr -> int requires (sizeof(decltype(x)) == 1) { return 0; }; -auto lambda3 = [] requires (sizeof(char) == 1) { }; +auto lambda3 = [] requires(sizeof(char) == 1){}; + +auto lambda4 = [] requires(sizeof(char) == 1){}; // expected-error {{expected body}} #if __cplusplus <= 202002L // expected-warning@-2{{is a C++2b extension}} #endif diff --git a/clang/test/Parser/cxx2a-template-lambdas.cpp b/clang/test/Parser/cxx2a-template-lambdas.cpp --- a/clang/test/Parser/cxx2a-template-lambdas.cpp +++ b/clang/test/Parser/cxx2a-template-lambdas.cpp @@ -7,3 +7,30 @@ auto L2 = [](T1 arg1, T2 arg2) -> T1 { }; auto L3 = [](auto arg) { T t; }; auto L4 = []() { }; + +// http://llvm.org/PR49736 +auto L5 = []{}; +auto L6 = [] noexcept {}; +#if __cplusplus <= 202002L +// expected-warning@-2 {{is a C++2b extension}} +#endif +auto L7 = [] requires true {}; // ? +auto L8 = [] requires true noexcept {}; +#if __cplusplus <= 202002L +// expected-warning@-2 {{is a C++2b extension}} +#endif + +auto L9 = [](){}; +auto L10 = []() noexcept {}; +auto L11 = [] requires true(){}; +auto L12 = [] requires true() noexcept {}; +auto L13 = [] requires true() noexcept requires true {}; +auto L14 = []() noexcept requires true {}; +auto L15 = [] requires true(){}; + +auto XL0 = [] noexcept requires true {}; // expected-error {{expected body}} +auto XL1 = [] noexcept requires true {}; // expected-error {{expected body}} +#if __cplusplus <= 202002L +// expected-warning@-3 {{is a C++2b extension}} +// expected-warning@-3 {{is a C++2b extension}} +#endif diff --git a/clang/test/Parser/cxx2b-lambdas.cpp b/clang/test/Parser/cxx2b-lambdas.cpp --- a/clang/test/Parser/cxx2b-lambdas.cpp +++ b/clang/test/Parser/cxx2b-lambdas.cpp @@ -18,8 +18,8 @@ auto L10 = [] noexcept { return true; }; auto L11 = [] -> bool { return true; }; auto L12 = [] consteval {}; -auto L13 = [] requires requires() { true; } -{}; +auto L13 = []() requires true {}; +auto L14 = [] requires true() requires true {}; auto L15 = [] [[maybe_unused]]{}; auto XL0 = [] mutable constexpr mutable {}; // expected-error{{cannot appear multiple times}} @@ -32,3 +32,11 @@ // expected-note{{to match this '('}} \ // expected-error{{expected body}} \ // expected-warning{{duplicate 'constexpr'}} + +// http://llvm.org/PR49736 +auto XL4 = [] requires true() {}; // expected-error{{expected body}} +auto XL5 = [] requires true {}; // expected-error{{expected body}} +auto XL6 = [] requires true requires true {}; // expected-error{{expected body}} +auto XL7 = [] requires true noexcept requires true {}; // expected-error{{expected body}} +auto XL8 = [] requires true requires true {}; // expected-error{{expected body}} +auto XL9 = [] requires true noexcept requires true {}; // expected-error{{expected body}}