aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2012-03-16 12:15:37 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2012-03-16 12:15:37 +0000
commit0961a01ebec0e31664bfe464bf4a0ac7b0891a1f (patch)
tree99f3e36f6dc5c7ceb3b343d5ccbc404d2cad4214
parente55329d6834647ba0e06f8a319e5d84c77310035 (diff)
Warn on flexible array members when in C89 mode, with -pedantic.
This fixes PR 4307. Patch by Eitan Adler! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152918 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticParseKinds.td2
-rw-r--r--lib/Sema/SemaDecl.cpp7
-rw-r--r--test/Sema/c89.c2
3 files changed, 11 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td
index 95522189e1..1f03a0777c 100644
--- a/include/clang/Basic/DiagnosticParseKinds.td
+++ b/include/clang/Basic/DiagnosticParseKinds.td
@@ -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">;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index ab1a1b4025..574c18c2e3 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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();
diff --git a/test/Sema/c89.c b/test/Sema/c89.c
index ac8c6e0b7b..25a10481e9 100644
--- a/test/Sema/c89.c
+++ b/test/Sema/c89.c
@@ -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'}} */