Warn on flexible array members when in C89 mode, with -pedantic.

This fixes PR 4307.

Patch by Eitan Adler!

llvm-svn: 152918
This commit is contained in:
David Chisnall
2012-03-16 12:15:37 +00:00
parent 8a5070213a
commit 07518f249f
3 changed files with 11 additions and 0 deletions

View File

@@ -56,6 +56,8 @@ def ext_c99_variable_decl_in_for_loop : Extension<
"variable declaration in for loop is a C99-specific feature">, InGroup<C99>;
def ext_c99_compound_literal : Extension<
"compound literals are a C99-specific feature">, InGroup<C99>;
def ext_c99_flexible_array_member : Extension<
"Flexible array members are a C99-specific feature">, InGroup<C99>;
def ext_enumerator_list_comma : Extension<
"commas at the end of enumerator lists are a %select{C99|C++11}0-specific "
"feature">;

View File

@@ -9483,6 +9483,13 @@ void Sema::ActOnFields(Scope* S,
else if (Fields.size() == 1)
Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate_gnu)
<< FD->getDeclName() << Record->getTagKind();
} else if (!getLangOpts().C99) {
if (Record->isUnion())
Diag(FD->getLocation(), diag::ext_flexible_array_union_gnu)
<< FD->getDeclName();
else
Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
<< FD->getDeclName() << Record->getTagKind();
} else if (NumNamedMembers < 1) {
Diag(FD->getLocation(), diag::err_flexible_array_empty_struct)
<< FD->getDeclName();

View File

@@ -90,4 +90,6 @@ void test16() {
printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
}
struct x { int x,y[]; }; /* expected-warning {{Flexible array members are a C99-specific feature}} */
void main() {} /* expected-error {{'main' must return 'int'}} */