[PATCH] D103595: [clang] Correct MarkFunctionReferenced for local class

Fütő Gergely via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 3 01:24:40 PDT 2021


futogergely created this revision.
futogergely added a reviewer: rsmith.
futogergely requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Minor correction after commit 4a941e25f2b57f85eef00a9cbfbc2569639570ad.

If during the instantiation of a local class a method of the
local class is referenced, don't try to instantiate it.

PR48839


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103595

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp


Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===================================================================
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -504,3 +504,24 @@
   }
   template void f<int>();
 }
+
+namespace PR48839 {
+  template <typename T>
+  void construct() {
+    T(0);
+  }
+
+  template <typename T>
+  void tester() {
+    struct d {
+      void test() {
+        construct<d>();
+    }
+    constexpr d(T b) : a(b) {}
+
+    T a;
+    };
+  }
+
+  void g() { tester<int>(); }
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17057,10 +17057,12 @@
           PointOfInstantiation = Loc;
         }
 
+        const bool isLocalClass =
+            isa<CXXRecordDecl>(Func->getDeclContext()) &&
+            cast<CXXRecordDecl>(Func->getDeclContext())->isLocalClass();
         if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
-            Func->isConstexpr()) {
-          if (isa<CXXRecordDecl>(Func->getDeclContext()) &&
-              cast<CXXRecordDecl>(Func->getDeclContext())->isLocalClass() &&
+            (!isLocalClass && Func->isConstexpr())) {
+          if (isLocalClass &&
               CodeSynthesisContexts.size())
             PendingLocalImplicitInstantiations.push_back(
                 std::make_pair(Func, PointOfInstantiation));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103595.349478.patch
Type: text/x-patch
Size: 1500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210603/fa0bae8d/attachment.bin>


More information about the cfe-commits mailing list