[PATCH] D106302: Implement P1937 consteval in unevaluated contexts
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 19 12:35:52 PDT 2021
cor3ntin created this revision.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
In an unevaluated contexts, consteval functions
should not be immediately evaluated.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106302
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/www/cxx_status.html
Index: clang/www/cxx_status.html
===================================================================
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1103,10 +1103,11 @@
<tr>
<td rowspan=2>Immediate functions (<tt>consteval</tt>)</td>
<td><a href="https://wg21.link/p1073r3">P1073R3</a></td>
- <td rowspan=2 class="none" align="center">No</td>
+ <td class="partial" align="center">Partial</td>
</tr>
<tr> <!-- from Prague -->
<td><a href="https://wg21.link/p1937r2">P1937R2</a></td>
+ <td class="unreleased" align="center">Clang 13</td>
</tr>
<tr>
<td><tt>std::is_constant_evaluated</tt></td>
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -594,3 +594,20 @@
}
} // namespace special_ctor
+
+namespace unevaluated {
+
+template <typename T, typename U> struct is_same { static const bool value = false; };
+template <typename T> struct is_same<T, T> { static const bool value = true; };
+
+long f(); //expected-note {{declared here}}
+auto consteval g(auto a) {
+ return a;
+}
+
+auto e = g(f()); // expected-error{{is not a constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}}
+
+using T = decltype(g(f()));
+static_assert(is_same<long, T>::value);
+
+} // namespace unevaluated
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16585,7 +16585,8 @@
}
ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
- if (!E.isUsable() || !Decl || !Decl->isConsteval() || isConstantEvaluated() ||
+ if (isUnevaluatedContext() || !E.isUsable() || !Decl ||
+ !Decl->isConsteval() || isConstantEvaluated() ||
RebuildingImmediateInvocation)
return E;
@@ -18702,8 +18703,8 @@
OdrUse = false;
if (auto *FD = dyn_cast<FunctionDecl>(E->getDecl()))
- if (!isConstantEvaluated() && FD->isConsteval() &&
- !RebuildingImmediateInvocation)
+ if (!isUnevaluatedContext() && !isConstantEvaluated() &&
+ FD->isConsteval() && !RebuildingImmediateInvocation)
ExprEvalContexts.back().ReferenceToConsteval.insert(E);
MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse,
RefsMinusAssignments);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106302.359883.patch
Type: text/x-patch
Size: 2521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210719/bdd5cbe2/attachment.bin>
More information about the cfe-commits
mailing list