]> granicus.if.org Git - clang/commitdiff
Parser: Array decls with static but without array size are illformed
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 8 Aug 2014 07:21:18 +0000 (07:21 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 8 Aug 2014 07:21:18 +0000 (07:21 +0000)
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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
test/Parser/declarators.c

index b2b4257a5d7c93190a4df893832f93995198235d..961c847084077195d79baefbcf5fc4c255cfea1a 100644 (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>;
index 727915c5a6c1cce980cae54a3f6381f49701f5fd..b4713659b4f94f8cd03740949178b4d94e232a2c 100644 (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.
index 39d9dc94490dfe2c5253b0adc832dc3c115a8d2f..c424d697353e38b6ccacfa194c9972a893eeee98 100644 (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))));