[PATCH] D66481: [C++20] Support for lambdas in unevaluated context

Kris Jusiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 08:38:48 PDT 2019


krzysztof-jusiak created this revision.
krzysztof-jusiak added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Problem:

- Lambdas in unevaluated context aren't supported in the newest clang yet but are required for our usage of jit.

Solution:

- Add support for lambdas in unevaluated context.


Repository:
  rC Clang

https://reviews.llvm.org/D66481

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp


Index: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp
===================================================================
--- clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp
@@ -15,9 +15,9 @@
 };
 
 void unevaluated_operand(P &p, int i) {
-  int i2 = sizeof([] ()->int { return 0; }()); // expected-error{{lambda expression in an unevaluated operand}}
+  int i2 = sizeof([] ()->int { return 0; }());
   const std::type_info &ti1 = typeid([&]() -> P& { return p; }());
-  const std::type_info &ti2 = typeid([&]() -> int { return i; }());  // expected-error{{lambda expression in an unevaluated operand}}
+  const std::type_info &ti2 = typeid([&]() -> int { return i; }());
 }
 
 template<typename T>
@@ -37,7 +37,7 @@
   // because the copy-initialization of the capture of boom_float occurs in an
   // unevaluated operand.
   const std::type_info &ti2
-    = typeid([=]() -> int { boom_float.tickle(); return 0; }()); // expected-error{{lambda expression in an unevaluated operand}}
+    = typeid([=]() -> int { boom_float.tickle(); return 0; }());
 
   auto foo = [=]() -> int { boom_double.tickle(); return 0; }; // expected-note{{in instantiation of member function 'Boom<double>::Boom' requested here}}
 }
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14577,18 +14577,7 @@
     if (Rec.ExprContext == ExpressionKind::EK_TemplateArgument || Rec.isUnevaluated() ||
         (Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus17)) {
       unsigned D;
-      if (Rec.isUnevaluated()) {
-        // C++11 [expr.prim.lambda]p2:
-        //   A lambda-expression shall not appear in an unevaluated operand
-        //   (Clause 5).
-        D = diag::err_lambda_unevaluated_operand;
-      } else if (Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus17) {
-        // C++1y [expr.const]p2:
-        //   A conditional-expression e is a core constant expression unless the
-        //   evaluation of e, following the rules of the abstract machine, would
-        //   evaluate [...] a lambda-expression.
-        D = diag::err_lambda_in_constant_expression;
-      } else if (Rec.ExprContext == ExpressionKind::EK_TemplateArgument) {
+        if (Rec.ExprContext == ExpressionKind::EK_TemplateArgument) {
         // C++17 [expr.prim.lamda]p2:
         // A lambda-expression shall not appear [...] in a template-argument.
         D = diag::err_lambda_in_invalid_context;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66481.216161.patch
Type: text/x-patch
Size: 2575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190820/619a834f/attachment.bin>


More information about the cfe-commits mailing list