[clang] [Clang][AST] Store injected template arguments in TemplateParameterList (PR #113579)

Krystian Stasiowski via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 25 10:33:32 PDT 2024


================
@@ -51,14 +51,15 @@ DefaultTemplateArgumentContainsUnexpandedPack(const TemplateParam &P) {
          P.getDefaultArgument().getArgument().containsUnexpandedParameterPack();
 }
 
-TemplateParameterList::TemplateParameterList(const ASTContext& C,
+TemplateParameterList::TemplateParameterList(const ASTContext &C,
                                              SourceLocation TemplateLoc,
                                              SourceLocation LAngleLoc,
                                              ArrayRef<NamedDecl *> Params,
                                              SourceLocation RAngleLoc,
                                              Expr *RequiresClause)
-    : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
-      NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
+    : InjectedArgs(&C), TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc),
----------------
sdkrystian wrote:

> This trickery with storing the ASTContext seems a little silly.

@erichkeane Is there any particular reason why? We already do something similar in e.g. `Redeclarable::DeclLink`. The injected template arguments are lazily allocated & cached, so we don't need the pointer to `ASTContext` once the injected template arguments have been allocated. Since we _can_ use a `PointerUnion` to store both values, I think adding yet another pointer to `TemplateParameterList` would be rather unjustified.

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


More information about the cfe-commits mailing list