[clang] Fix missing initializer for inline static template member with auto caused by delayed template instantiation. (PR #138122)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Thu May 8 17:14:00 PDT 2025


================
@@ -6027,8 +6027,15 @@ void Sema::BuildVariableInstantiation(
   Context.setManglingNumber(NewVar, Context.getManglingNumber(OldVar));
   Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar));
 
+  bool VarTemplateWithAutoType = false;
+  QualType VarSourceType = OldVar->getTypeSourceInfo()->getType();
+  if (VarSourceType->getAs<AutoType>()) {
+    VarTemplateWithAutoType = true;
+  }
+
   // Figure out whether to eagerly instantiate the initializer.
-  if (InstantiatingVarTemplate || InstantiatingVarTemplatePartialSpec) {
+  if ((InstantiatingVarTemplate && !VarTemplateWithAutoType) ||
+      InstantiatingVarTemplatePartialSpec) {
     // We're producing a template. Don't instantiate the initializer yet.
   } else if (NewVar->getType()->isUndeducedType()) {
     // We need the type to complete the declaration of the variable.
----------------
zyn0217 wrote:

I don't understand what "strategy" is going to be violated. So you have an example?

https://github.com/llvm/llvm-project/pull/138122


More information about the cfe-commits mailing list