Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ def warn_empty_init_statement : Warning<
"has no effect">, InGroup<EmptyInitStatement>, DefaultIgnore;
def err_keyword_as_parameter : Error <
"invalid parameter name: '%0' is a keyword">;
def warn_pre_cxx26_ambiguous_pack_indexing_type : Warning<
"parameter packs without specifying a name would become a pack indexing "
"declaration in C++2c onwards">, InGroup<CXXPre26Compat>;
def note_add_a_name_to_pre_cxx26_parameter_packs : Note<
"add a name to disambiguate">;

// C++ derived classes
def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;
Expand Down
18 changes: 18 additions & 0 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,25 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
SourceLocation Start = Tok.getLocation();
DeclSpec DS(AttrFactory);
SourceLocation CCLoc;
TentativeParsingAction MaybePackIndexing(*this, /*Unannotated=*/true);
SourceLocation EndLoc = ParsePackIndexingType(DS);
// C++ [cpp23.dcl.dcl-2]:
// Previously, T...[n] would declare a pack of function parameters.
// T...[n] is now a pack-index-specifier. [...] Valid C++ 2023 code that
// declares a pack of parameters without specifying a declarator-id
// becomes ill-formed.
if (!Tok.is(tok::coloncolon) && !getLangOpts().CPlusPlus26 &&
getCurScope()->isFunctionDeclarationScope()) {
Diag(DS.getEllipsisLoc(),
diag::warn_pre_cxx26_ambiguous_pack_indexing_type);
Diag(DS.getEllipsisLoc(),
diag::note_add_a_name_to_pre_cxx26_parameter_packs);
MaybePackIndexing.Revert();
return false;
}

MaybePackIndexing.Commit();

if (DS.getTypeSpecType() == DeclSpec::TST_error)
return false;

Expand Down
5 changes: 3 additions & 2 deletions clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ void b(T[] ...);

template<typename T>
void c(T ... []); // expected-error {{expected expression}} \
// expected-error {{'T' does not refer to the name of a parameter pack}} \
// expected-warning {{pack indexing is a C++2c extension}}
// expected-error {{type 'T[]' of function parameter pack does not contain any unexpanded parameter packs}} \
// expected-warning {{would become a pack indexing declaration in C++2c onwards}} \
// expected-note {{add a name to disambiguate}}

template<typename T>
void d(T ... x[]); // expected-error{{type 'T[]' of function parameter pack does not contain any unexpanded parameter packs}}
Expand Down
8 changes: 2 additions & 6 deletions clang/test/Parser/cxx0x-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,8 @@ struct MemberComponentOrder : Base {
void NoMissingSemicolonHere(struct S
[3]);
template<int ...N> void NoMissingSemicolonHereEither(struct S... [N]);
// expected-error@-1 {{'S' does not refer to the name of a parameter pack}} \
// expected-error@-1 {{declaration of anonymous struct must be a definition}} \
// expected-error@-1 {{expected parameter declarator}} \
// expected-error@-1 {{pack indexing is a C++2c extension}} \


// expected-warning@-1 {{parameter packs without specifying a name would become a pack indexing declaration in C++2c onwards}} \
// expected-note@-1 {{add a name to disambiguate}}

// This must be at the end of the file; we used to look ahead past the EOF token here.
// expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}
Expand Down
24 changes: 24 additions & 0 deletions clang/test/SemaCXX/cxx2c-pack-indexing-ext-diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,27 @@ void f(T... t) {
// cxx11-warning@+1 {{pack indexing is a C++2c extension}}
T...[0] c;
}

template <typename... T>
void g(T... [1]); // cxx11-warning {{parameter packs without specifying a name would become a pack indexing declaration in C++2c onwards}} \
// cxx11-note {{add a name to disambiguate}} \
// cxx26-warning {{pack indexing is incompatible with C++ standards before C++2c}} \
// cxx26-note {{candidate function template not viable}}

template <typename... T>
void h(T... param[1]);

template <class T>
struct S {
using type = T;
};

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

void call() {
g<int, double>(nullptr, nullptr); // cxx26-error {{no matching function for call to 'g'}}
h<int, double>(nullptr, nullptr);
h<S<int>, S<const char *>>("hello");
}
Loading