curdeius created this revision.
curdeius added reviewers: aaron.ballman, rsmith.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes http://llvm.org/PR49736 caused by implementing 
http://wg21.link/P1102 
(https://reviews.llvm.org/rG0620e6f4b76a9725dbd82454d58c5a68a7e47074), by 
correctly allowing requires-clause only:

1. directly after template-parameter-list
2. after lambda-specifiers iff parameter-declaration-clause is present (2nd 
kind of lambda-declarator)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99489

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/cxx-concepts-requires-clause.cpp
  clang/test/Parser/cxx2a-template-lambdas.cpp
  clang/test/Parser/cxx2b-lambdas.cpp

Index: clang/test/Parser/cxx2b-lambdas.cpp
===================================================================
--- clang/test/Parser/cxx2b-lambdas.cpp
+++ clang/test/Parser/cxx2b-lambdas.cpp
@@ -18,8 +18,8 @@
 auto L10 = []<typename T> noexcept { return true; };
 auto L11 = []<typename T> -> bool { return true; };
 auto L12 = [] consteval {};
-auto L13 = [] requires requires() { true; }
-{};
+auto L13 = []() requires true {};
+auto L14 = []<auto> 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 = []<auto> requires true requires true {}; // expected-error{{expected body}}
+auto XL9 = []<auto> requires true noexcept requires true {}; // expected-error{{expected body}}
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===================================================================
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -7,3 +7,30 @@
 auto L2 = []<typename T1, typename T2>(T1 arg1, T2 arg2) -> T1 { };
 auto L3 = []<typename T>(auto arg) { T t; };
 auto L4 = []<int I>() { };
+
+// http://llvm.org/PR49736
+auto L5 = []<auto>{};
+auto L6 = []<auto> noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L7 = []<auto> requires true {}; // ?
+auto L8 = []<auto> requires true noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+
+auto L9 = []<auto>(){};
+auto L10 = []<auto>() noexcept {};
+auto L11 = []<auto> requires true(){};
+auto L12 = []<auto> requires true() noexcept {};
+auto L13 = []<auto> requires true() noexcept requires true {};
+auto L14 = []<auto>() noexcept requires true {};
+auto L15 = []<auto> requires true(){};
+
+auto XL0 = []<auto> noexcept requires true {}; // expected-error {{expected body}}
+auto XL1 = []<auto> 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
Index: clang/test/Parser/cxx-concepts-requires-clause.cpp
===================================================================
--- clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ 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 = []<auto> 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
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ 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<DeclaratorChunk::ParamInfo> EmptyParamInfo;
     ParseLambdaSpecifiers(/*LParenLoc=*/NoLoc, /*RParenLoc=*/NoLoc,
                           EmptyParamInfo, /*EllipsisLoc=*/NoLoc);
+
+    WarnIfHasCUDATargetAttr();
   }
 
   // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to