PR15311: Finish implementation of the suggested resolution of core issue 1488,

which allows grouping parens in an abstract-pack-declarator. This was already
mostly implemented, but missed some cases. Add an ExtWarn for use of this
extension until CWG ratifies it.

llvm-svn: 175660
This commit is contained in:
Richard Smith 2013-02-20 20:19:27 +00:00
parent 1366a61242
commit b19337fbe4
4 changed files with 15 additions and 2 deletions

View File

@ -470,6 +470,9 @@ def err_parser_impl_limit_overflow : Error<
def err_misplaced_ellipsis_in_declaration : Error<
"'...' must %select{immediately precede declared identifier|"
"be innermost component of anonymous pack declaration}0">;
def ext_abstract_pack_declarator_parens : ExtWarn<
"ISO C++11 requires a parenthesized pack declaration to have a name">,
InGroup<DiagGroup<"anonymous-pack-parens">>;
// C++ derived classes
def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;

View File

@ -4439,6 +4439,7 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
!((D.getContext() == Declarator::PrototypeContext ||
D.getContext() == Declarator::BlockLiteralContext) &&
NextToken().is(tok::r_paren) &&
!D.hasGroupingParens() &&
!Actions.containsUnexpandedParameterPacks(D))) {
SourceLocation EllipsisLoc = ConsumeToken();
if (isPtrOperatorToken(Tok.getKind(), getLangOpts())) {
@ -4521,6 +4522,12 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
// This could be something simple like "int" (in which case the declarator
// portion is empty), if an abstract-declarator is allowed.
D.SetIdentifier(0, Tok.getLocation());
// The grammar for abstract-pack-declarator does not allow grouping parens.
// FIXME: Revisit this once core issue 1488 is resolved.
if (D.hasEllipsis() && D.hasGroupingParens())
Diag(PP.getLocForEndOfToken(D.getEllipsisLoc()),
diag::ext_abstract_pack_declarator_parens);
} else {
if (Tok.getKind() == tok::annot_pragma_parser_crash)
LLVM_BUILTIN_TRAP;

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -verify -std=c++11 %s
// RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s
// RUN: cp %s %t
// RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t
// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t

View File

@ -110,7 +110,7 @@ namespace ellipsis {
void f(S(...args[sizeof(T)])); // expected-note {{here}}
void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}} expected-note {{here}}
void f(S ...args[sizeof(T)]); // expected-error {{redeclared}}
void g(S(...[sizeof(T)])); // expected-note {{here}}
void g(S(...[sizeof(T)])); // expected-note {{here}} expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
void g(S(...)[sizeof(T)]); // expected-error {{function cannot return array type}}
void g(S ...[sizeof(T)]); // expected-error {{redeclared}}
void h(T(...)); // function type, expected-error {{unexpanded parameter pack}}
@ -125,5 +125,8 @@ namespace ellipsis {
void j(T(T...)); // expected-error {{unexpanded parameter pack}}
void k(int(...)(T)); // expected-error {{cannot return function type}}
void k(int ...(T));
void l(int(&...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
void l(int(*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
void l(int(S<int>::*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
};
}