From: David Chisnall Date: Fri, 16 Mar 2012 12:15:37 +0000 (+0000) Subject: Warn on flexible array members when in C89 mode, with -pedantic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0961a01ebec0e31664bfe464bf4a0ac7b0891a1f;p=clang 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 --- 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; def ext_c99_compound_literal : Extension< "compound literals are a C99-specific feature">, InGroup; +def ext_c99_flexible_array_member : Extension< + "Flexible array members are a C99-specific feature">, InGroup; 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'}} */