Skip to content

Commit 0ba59a7

Browse files
committed
Address the feedback
1 parent c48988a commit 0ba59a7

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,8 @@ def warn_empty_init_statement : Warning<
719719
def err_keyword_as_parameter : Error <
720720
"invalid parameter name: '%0' is a keyword">;
721721
def warn_pre_cxx26_ambiguous_pack_indexing_type : Warning<
722-
"parameter packs without specifying a name would become a pack indexing "
723-
"declaration in C++2c onwards">, InGroup<CXXPre26Compat>;
724-
def note_add_a_name_to_pre_cxx26_parameter_packs : Note<
725-
"add a name to disambiguate">;
722+
"%0 is no longer a pack expansion but a pack "
723+
"indexing type; add a name to specify a pack expansion">, InGroup<CXXPre26Compat>;
726724

727725
// C++ derived classes
728726
def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

clang/test/Parser/cxx0x-decl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,12 @@ struct MemberComponentOrder : Base {
214214
void NoMissingSemicolonHere(struct S
215215
[3]);
216216
template<int ...N> void NoMissingSemicolonHereEither(struct S... [N]);
217-
// expected-warning@-1 {{parameter packs without specifying a name would become a pack indexing declaration in C++2c onwards}} \
218-
// expected-note@-1 {{add a name to disambiguate}}
217+
// expected-warning@-1 {{'S...[N]' is no longer a pack expansion but a pack indexing type; add a name to specify a pack expansion}} \
218+
// expected-error@-1 {{'S' does not refer to the name of a parameter pack}} \
219+
// expected-error@-1 {{declaration of anonymous struct must be a definition}} \
220+
// expected-error@-1 {{expected parameter declarator}} \
221+
// expected-error@-1 {{pack indexing is a C++2c extension}} \
222+
219223

220224
// This must be at the end of the file; we used to look ahead past the EOF token here.
221225
// expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}

clang/test/SemaCXX/cxx2c-pack-indexing-ext-diags.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ void f(T... t) {
2121
}
2222

2323
template <typename... T>
24-
void g(T... [1]); // cxx11-warning {{parameter packs without specifying a name would become a pack indexing declaration in C++2c onwards}} \
25-
// cxx11-note {{add a name to disambiguate}} \
24+
void g(T... [1]); // cxx11-warning {{'T...[1]' is no longer a pack expansion but a pack indexing type; add a name to specify a pack expansion}} \
25+
// cxx11-warning {{pack indexing is a C++2c extension}} \
26+
// cxx11-note {{candidate function template not viable}} \
2627
// cxx26-warning {{pack indexing is incompatible with C++ standards before C++2c}} \
2728
// cxx26-note {{candidate function template not viable}}
2829

@@ -38,8 +39,14 @@ template <typename... T>
3839
void h(typename T... [1]::type); // cxx11-warning {{pack indexing is a C++2c extension}} \
3940
// cxx26-warning {{pack indexing is incompatible with C++ standards before C++2c}}
4041

42+
template <typename... T>
43+
void x(T... [0]); // cxx11-warning {{'T...[0]' is no longer a pack expansion but a pack indexing type; add a name to specify a pack expansion}} \
44+
// cxx26-warning {{pack indexing is incompatible with C++ standards before C++2c}}
45+
4146
void call() {
42-
g<int, double>(nullptr, nullptr); // cxx26-error {{no matching function for call to 'g'}}
47+
g<int, double>(nullptr, nullptr); // cxx26-error {{no matching function for call to 'g'}} \
48+
// cxx11-error {{no matching function for call to 'g'}}
4349
h<int, double>(nullptr, nullptr);
4450
h<S<int>, S<const char *>>("hello");
51+
x<int*>(nullptr);
4552
}

0 commit comments

Comments
 (0)