=?utf-8?q?Balázs_Kéri?= <balazs.k...@ericsson.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/101...@github.com>
================ @@ -5968,11 +5962,21 @@ ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { } if (D->hasDefaultArgument()) { + // Default argument can be "inherited" when it has a reference to the + // previous declaration (of the default argument) which is stored only once. + // Here we import the default argument in any case, and the inherited state + // is updated later after the parent template was created. If the + // inherited-from object would be imported here it causes more difficulties + // (parent template may not be created yet and import loops can occur). Expected<TemplateArgumentLoc> ToDefaultArgOrErr = import(D->getDefaultArgument()); if (!ToDefaultArgOrErr) return ToDefaultArgOrErr.takeError(); - ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr); + // The just called import process can trigger import of the parent template + // which can update the default argument value to "inherited". This should + // not be changed. + if (!ToD->hasDefaultArgument()) + ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr); ---------------- mizvekov wrote: I think it's important preserving the default argument inheritance chain order, by importing it explicitly and disabling the automatic inheritance during import. The default argument can only be used if it has been declared before use, in source code parsing order. It seems like it would create difficulties parsing the AST if this order becomes arbitrary. For example: https://godbolt.org/z/cx9jf5nso https://github.com/llvm/llvm-project/pull/101836 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits