[PATCH] D119375: [Clang][Sema] Do not evaluate value-dependent immediate invocations
Evgeny Shulgin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 10 02:55:24 PST 2022
Izaron updated this revision to Diff 407449.
Izaron added a comment.
Fix comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119375/new/
https://reviews.llvm.org/D119375
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -613,6 +613,26 @@
} // namespace unevaluated
+namespace value_dependent {
+
+consteval int foo(int x) {
+ return x;
+}
+
+template <int X> constexpr int bar() {
+ return foo(X);
+}
+
+template <typename T> constexpr int baz() {
+ constexpr int t = sizeof(T);
+ return foo(t);
+}
+
+static_assert(bar<15>() == 15);
+static_assert(baz<int>() == sizeof(int));
+
+} // namespace value_dependent
+
namespace PR50779 {
struct derp {
int b = 0;
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16747,7 +16747,10 @@
ConstantExpr::getStorageKind(Decl->getReturnType().getTypePtr(),
getASTContext()),
/*IsImmediateInvocation*/ true);
- ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
+ /// Value-dependent constant expressions should not be immediately
+ /// evaluated until they are instantiated.
+ if (!Res->isValueDependent())
+ ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
return Res;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119375.407449.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220210/3e77efb1/attachment.bin>
More information about the cfe-commits
mailing list