[PATCH] D102102: [clang] Instantiate the initializer of variable templates eagerly

Natsu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 8 03:19:25 PDT 2021


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

This patch fixes the bug shown in https://godbolt.org/z/d4a1Kz7r8


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102102

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4974,11 +4974,6 @@
     LocalInstantiationScope *StartingScope,
     bool InstantiatingVarTemplate,
     VarTemplateSpecializationDecl *PrevDeclForVarTemplateSpecialization) {
-  // Instantiating a partial specialization to produce a partial
-  // specialization.
-  bool InstantiatingVarTemplatePartialSpec =
-      isa<VarTemplatePartialSpecializationDecl>(OldVar) &&
-      isa<VarTemplatePartialSpecializationDecl>(NewVar);
   // Instantiating from a variable template (or partial specialization) to
   // produce a variable template specialization.
   bool InstantiatingSpecFromTemplate =
@@ -5075,9 +5070,7 @@
   Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar));
 
   // Figure out whether to eagerly instantiate the initializer.
-  if (InstantiatingVarTemplate || InstantiatingVarTemplatePartialSpec) {
-    // We're producing a template. Don't instantiate the initializer yet.
-  } else if (NewVar->getType()->isUndeducedType()) {
+  if (NewVar->getType()->isUndeducedType()) {
     // We need the type to complete the declaration of the variable.
     InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
   } else if (InstantiatingSpecFromTemplate ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102102.343825.patch
Type: text/x-patch
Size: 1424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210508/743c5321/attachment-0001.bin>


More information about the cfe-commits mailing list