From: David Majnemer Date: Fri, 8 Aug 2014 07:21:18 +0000 (+0000) Subject: Parser: Array decls with static but without array size are illformed X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16a9476fd64618df5d883b80553a9115a61fe2c5;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215187 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index b2b4257a5d..961c847084 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -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; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 727915c5a6..b4713659b4 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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. diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c index 39d9dc9449..c424d69735 100644 --- a/test/Parser/declarators.c +++ b/test/Parser/declarators.c @@ -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))));