diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-08-08 07:21:18 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-08-08 07:21:18 +0000 |
commit | f9834d5fa0944872a662eca971fb216058d2514d (patch) | |
tree | 39f81f9c71edd98cf4f2aa67ca35aee20d43f23f | |
parent | 88d6dc962ab3b9f8b7bf8605dd77fdaef9f10800 (diff) | |
download | bcm5719-llvm-f9834d5fa0944872a662eca971fb216058d2514d.tar.gz bcm5719-llvm-f9834d5fa0944872a662eca971fb216058d2514d.zip |
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
-rw-r--r-- | clang/include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 5 | ||||
-rw-r--r-- | clang/test/Parser/declarators.c | 1 |
3 files changed, 8 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index b2b4257a5d7..961c8470840 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/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<DeprecatedRegister>; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 727915c5a6c..b4713659b4f 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/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/clang/test/Parser/declarators.c b/clang/test/Parser/declarators.c index 39d9dc94490..c424d697353 100644 --- a/clang/test/Parser/declarators.c +++ b/clang/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)))); |