Skip to content

Conversation

@sdkrystian
Copy link
Member

Previously, ParseOptionalCXXScopeSpecifier only handled pack-index-specifiers where the pattern was a simple identifier (e.g., T...[0]::). This patch adds support for template-id patterns (e.g., Foo<T>...[0]::).

The fix involves two parts:

  1. Extend ParsePackIndexingType to handle tok::annot_template_id in addition to tok::identifier.
  2. Add handling inside the loop in ParseOptionalCXXScopeSpecifier for annot_template_id followed by ... [ constant-expression ].

This fixes code like:

  template<template<class...> class... L> void f() {
    using T = mp_quote<L>...[0]::template fn<void>;
  }

which previously failed to parse.

@sdkrystian sdkrystian force-pushed the pack-template-id-parse branch from 17c8a8b to b7e5531 Compare January 28, 2026 16:18
@sdkrystian sdkrystian force-pushed the pack-template-id-parse branch from b7e5531 to 5b04344 Compare January 28, 2026 16:19
Comment on lines +1195 to +1201
getCurScope(), ElaboratedTypeKeyword::None,
/*ElaboratedKeywordLoc=*/SourceLocation(), SS,
TemplateId->TemplateKWLoc, TemplateId->Template,
TemplateId->Name, TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc, TemplateArgsPtr, TemplateId->RAngleLoc,
/*IsCtorOrDtorName=*/false, /*IsClassName=*/false,
ImplicitTypenameContext::No);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs rewiring for nested name and elaborated keyword support, with additional tests covering those cases.

AST dump tests and ast-print roundtrip tests would make good confirmation this works.

Copy link

@Endilll Endilll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I see that pack indexing is handled before the loop in ParseOptionalCXXScopeSpecifier, too:

    SourceLocation EndLoc = ParsePackIndexingType(DS);

    I'm not sure we need to touch it, but would be nice if description touched on that

  2. Would be nice to mention somewhere that previously only the identifier form of typedef-name within pack-index-specifier was handled, but this PR handles simple-template-id form of typedef-name.

  3. "template-id" in the title mislead me to believe that this is covering not just simple-template-id, but also operator-function-id < template-argument-list (opt)> and literal-operator-id < template-argument-list (opt) >. This is not the case, and it would be nice to have couple more tests that make sure those forms of template-id are not accepted within pack-index-specifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants