================ @@ -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. ---------------- dty2 wrote:
Thank you for your review. I think the two if statements should not be swapped, because clang adopts the strategy of delaying template instantiation. If the two if statements are swapped, it will completely violate this strategy. Therefore, I do not plan to swap the two if statements, but only pre-instantiate the template variables of auto type. Of course, if there are other reasons or my understanding is wrong, please let me know and I will consider it again. In addition, thank you again for reminding me to handle some specialized templates, so I modified the if statement to handle this situation. https://github.com/llvm/llvm-project/pull/138122 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits