[PATCH] D103380: [C++20] Support for lambdas in unevaluated context
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 30 05:40:42 PDT 2021
cor3ntin created this revision.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Partially implement P0315R4.
This patch allow lambda in unevaluated context.
It does not implement temp.deduct/9.
This is a rewrite of https://reviews.llvm.org/D66481 that did
not see progress over the past 2 years.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103380
Files:
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp
clang/test/SemaCXX/anonymous-struct.cpp
clang/www/cxx_status.html
Index: clang/www/cxx_status.html
===================================================================
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1011,7 +1011,7 @@
<tr>
<td>Lambdas in unevaluated contexts</td>
<td><a href="https://wg21.link/p0315r4">P0315R4</a></td>
- <td class="none" align="center">No</td>
+ <td class="partial" align="center">Clang 13</td>
</tr>
<!-- Jacksonville papers -->
<tr>
Index: clang/test/SemaCXX/anonymous-struct.cpp
===================================================================
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -49,7 +49,7 @@
: B { // expected-note {{type is not C-compatible due to this base class}}
} C; // expected-note {{type is given name 'C' for linkage purposes by this typedef declaration}}
-#if __cplusplus > 201703L
+#if __cplusplus > 201703L && __cplusplus < 202002L
typedef struct { // expected-warning {{anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here}}
static_assert([]{ return true; }()); // expected-note {{type is not C-compatible due to this lambda expression}}
} Lambda1; // expected-note {{type is given name 'Lambda1' for linkage purposes by this typedef declaration}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp
===================================================================
--- /dev/null
+++ clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2-unevaluated.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 %s -verify
+// expected-no-diagnostics
+
+template<auto> struct Nothing {};
+
+template<typename T>
+concept True = [] { return true; }();
+
+static_assert(True<int>);
+
+using x = decltype([] { return 0;}());
+
+Nothing<[]() { return 0; }()> nothing;
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16657,8 +16657,8 @@
if (!Rec.Lambdas.empty()) {
using ExpressionKind = ExpressionEvaluationContextRecord::ExpressionKind;
- if (Rec.ExprContext == ExpressionKind::EK_TemplateArgument || Rec.isUnevaluated() ||
- (Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus17)) {
+ if (!getLangOpts().CPlusPlus20 && (Rec.ExprContext == ExpressionKind::EK_TemplateArgument || Rec.isUnevaluated() ||
+ (Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus17))) {
unsigned D;
if (Rec.isUnevaluated()) {
// C++11 [expr.prim.lambda]p2:
Index: clang/lib/Sema/SemaConcept.cpp
===================================================================
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -41,9 +41,11 @@
LHS = BO->getLHS();
RHS = BO->getRHS();
} else if (auto *OO = dyn_cast<CXXOperatorCallExpr>(E)) {
- Op = OO->getOperator();
- LHS = OO->getArg(0);
- RHS = OO->getArg(1);
+ if(OO->getNumArgs() == 2) {
+ Op = OO->getOperator();
+ LHS = OO->getArg(0);
+ RHS = OO->getArg(1);
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103380.348692.patch
Type: text/x-patch
Size: 3148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210530/7d35cdb4/attachment-0001.bin>
More information about the cfe-commits
mailing list