@@ -243,25 +243,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
243243 SourceLocation Start = Tok.getLocation ();
244244 DeclSpec DS (AttrFactory);
245245 SourceLocation CCLoc;
246- TentativeParsingAction MaybePackIndexing (*this , /* Unannotated=*/ true );
247246 SourceLocation EndLoc = ParsePackIndexingType (DS);
248- // C++ [cpp23.dcl.dcl-2]:
249- // Previously, T...[n] would declare a pack of function parameters.
250- // T...[n] is now a pack-index-specifier. [...] Valid C++ 2023 code that
251- // declares a pack of parameters without specifying a declarator-id
252- // becomes ill-formed.
253- if (!Tok.is (tok::coloncolon) && !getLangOpts ().CPlusPlus26 &&
254- getCurScope ()->isFunctionDeclarationScope ()) {
255- Diag (DS.getEllipsisLoc (),
256- diag::warn_pre_cxx26_ambiguous_pack_indexing_type);
257- Diag (DS.getEllipsisLoc (),
258- diag::note_add_a_name_to_pre_cxx26_parameter_packs);
259- MaybePackIndexing.Revert ();
260- return false ;
261- }
262-
263- MaybePackIndexing.Commit ();
264-
265247 if (DS.getTypeSpecType () == DeclSpec::TST_error)
266248 return false ;
267249
@@ -272,6 +254,19 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
272254 if (Type.isNull ())
273255 return false ;
274256
257+ // C++ [cpp23.dcl.dcl-2]:
258+ // Previously, T...[n] would declare a pack of function parameters.
259+ // T...[n] is now a pack-index-specifier. [...] Valid C++ 2023 code that
260+ // declares a pack of parameters without specifying a declarator-id
261+ // becomes ill-formed.
262+ //
263+ // However, we still avoid parsing them as pack expansions because this is a
264+ // rare use case of packs, despite being partway non-conforming, to ensure
265+ // semantic consistency given that we have backported this feature.
266+ if (!Tok.is (tok::coloncolon) && !getLangOpts ().CPlusPlus26 &&
267+ getCurScope ()->isFunctionDeclarationScope ())
268+ Diag (Start, diag::warn_pre_cxx26_ambiguous_pack_indexing_type) << Type;
269+
275270 if (!TryConsumeToken (tok::coloncolon, CCLoc)) {
276271 AnnotateExistingIndexedTypeNamePack (ParsedType::make (Type), Start,
277272 EndLoc);
0 commit comments