[PATCH] D132031: Do not evaluate dependent immediate invocations

Utkarsh Saxena via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 08:01:08 PDT 2022


usaxena95 created this revision.
Herald added a project: All.
usaxena95 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We deferred the evaluation of dependent immediate invocations in https://reviews.llvm.org/D119375.
We should also not consider them referenced from a non-consteval
context.

Fixes: https://github.com/llvm/llvm-project/issues/55601


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132031

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
@@ -649,6 +649,21 @@
 static_assert(bar<15>() == 15);
 static_assert(baz<int>() == sizeof(int));
 
+
+namespace issue_55601 {
+template<typename T>
+class Bar {
+  // Dependent immmediate expressions should be evaluated at instantiation. 
+  consteval static T x() { return 5; }
+ public:
+  Bar() : a(x()) {}
+
+ private:
+  int a;
+};
+Bar<int> f;
+Bar<float> g;
+} // namespace issue_55601
 } // namespace value_dependent
 
 namespace default_argument {
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19673,10 +19673,10 @@
     if (Method->isVirtual() &&
         !Method->getDevirtualizedMethod(Base, getLangOpts().AppleKext))
       OdrUse = false;
-
   if (auto *FD = dyn_cast<FunctionDecl>(E->getDecl()))
     if (!isUnevaluatedContext() && !isConstantEvaluated() &&
-        FD->isConsteval() && !RebuildingImmediateInvocation)
+        FD->isConsteval() && !RebuildingImmediateInvocation &&
+        !FD->isDependentContext())
       ExprEvalContexts.back().ReferenceToConsteval.insert(E);
   MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse,
                      RefsMinusAssignments);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132031.453287.patch
Type: text/x-patch
Size: 1440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220817/015f1600/attachment.bin>


More information about the cfe-commits mailing list