r215187 - Parser: Array decls with static but without array size are illformed
David Majnemer
david.majnemer at gmail.com
Fri Aug 8 00:21:18 PDT 2014
Author: majnemer
Date: Fri Aug 8 02:21:18 2014
New Revision: 215187
URL: http://llvm.org/viewvc/llvm-project?rev=215187&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/Parser/declarators.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=215187&r1=215186&r2=215187&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Aug 8 02:21:18 2014
@@ -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>;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=215187&r1=215186&r2=215187&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Aug 8 02:21:18 2014
@@ -5596,6 +5596,11 @@ void Parser::ParseBracketDeclarator(Decl
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.
Modified: cfe/trunk/test/Parser/declarators.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/declarators.c?rev=215187&r1=215186&r2=215187&view=diff
==============================================================================
--- cfe/trunk/test/Parser/declarators.c (original)
+++ cfe/trunk/test/Parser/declarators.c Fri Aug 8 02:21:18 2014
@@ -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))));
More information about the cfe-commits
mailing list