Parser: Array decls with static but without array size are illformed

Array declarators involving the static keyword take on two forms:
    D[ static type-qualifier-listopt assignment-expression ]
    D[ type-qualifier-list static assignment-expression ]

Raise a diagnostic if the assignment-expression is missing.

This fixes PR20584.

llvm-svn: 215187
This commit is contained in:
David Majnemer 2014-08-08 07:21:18 +00:00
parent 88d6dc962a
commit f9834d5fa0
3 changed files with 8 additions and 0 deletions

View File

@ -306,6 +306,8 @@ def err_expected_class_name_not_template :
Error<"'typename' is redundant; base classes are implicitly types">;
def err_unspecified_vla_size_with_static : Error<
"'static' may not be used with an unspecified variable length array size">;
def err_unspecified_size_with_static : Error<
"'static' may not be used without an array size">;
def warn_deprecated_register : Warning<
"'register' storage class specifier is deprecated">,
InGroup<DeprecatedRegister>;

View File

@ -5596,6 +5596,11 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
Sema::ConstantEvaluated);
NumElements = ParseAssignmentExpression();
}
} else {
if (StaticLoc.isValid()) {
Diag(StaticLoc, diag::err_unspecified_size_with_static);
StaticLoc = SourceLocation(); // Drop the static.
}
}
// If there was an error parsing the assignment-expression, recover.

View File

@ -7,6 +7,7 @@ void f1(int [*]);
void f2(int [const *]);
void f3(int [volatile const*]);
int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */
int f5(int [static]); /* expected-error {{'static' may not be used without an array size}} */
char ((((*X))));