r193918 - Sema: Flexible array members were introduced in C99, diagnose their use in C++
David Majnemer
david.majnemer at gmail.com
Sat Nov 2 02:22:44 PDT 2013
Author: majnemer
Date: Sat Nov 2 04:22:44 2013
New Revision: 193918
URL: http://llvm.org/viewvc/llvm-project?rev=193918&view=rev
Log:
Sema: Flexible array members were introduced in C99, diagnose their use in C++
The declaration of a flexible array member was correctly diagnosed as an
extension in C89 mode but not in C++.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/c89.c
cfe/trunk/test/SemaCXX/c99.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=193918&r1=193917&r2=193918&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sat Nov 2 04:22:44 2013
@@ -74,7 +74,7 @@ def ext_c99_variable_decl_in_for_loop :
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>;
+ "flexible array members are a C99-specific feature">, InGroup<C99>;
def ext_enumerator_list_comma_c : Extension<
"commas at the end of enumerator lists are a C99-specific "
"feature">, InGroup<C99>;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=193918&r1=193917&r2=193918&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Nov 2 04:22:44 2013
@@ -11829,6 +11829,9 @@ void Sema::ActOnFields(Scope *S, SourceL
else if (Fields.size() == 1)
Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate_ms)
<< FD->getDeclName() << Record->getTagKind();
+ else
+ Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
+ << FD->getDeclName() << Record->getTagKind();
} else if (getLangOpts().CPlusPlus) {
if (Record->isUnion())
Diag(FD->getLocation(), diag::ext_flexible_array_union_gnu)
@@ -11836,6 +11839,9 @@ void Sema::ActOnFields(Scope *S, SourceL
else if (Fields.size() == 1)
Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate_gnu)
<< FD->getDeclName() << Record->getTagKind();
+ else
+ Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
+ << FD->getDeclName() << Record->getTagKind();
} else if (!getLangOpts().C99) {
if (Record->isUnion())
Diag(FD->getLocation(), diag::ext_flexible_array_union_gnu)
Modified: cfe/trunk/test/Sema/c89.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89.c?rev=193918&r1=193917&r2=193918&view=diff
==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Sat Nov 2 04:22:44 2013
@@ -90,7 +90,7 @@ 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}} */
+struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99-specific feature}} */
/* Duplicated type-qualifiers aren't allowed by C90 */
const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
Modified: cfe/trunk/test/SemaCXX/c99.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c99.cpp?rev=193918&r1=193917&r2=193918&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/c99.cpp (original)
+++ cfe/trunk/test/SemaCXX/c99.cpp Sat Nov 2 04:22:44 2013
@@ -2,7 +2,7 @@
void f1(int i[static 5]) { // expected-error{{C99}}
}
-struct Point { int x; int y; };
+struct Point { int x; int y; int z[]; }; // expected-warning{{flexible array members are a C99-specific feature}}
Point p1 = { .x = 17, // expected-warning{{designated initializers are a C99 feature}}
y: 25 }; // expected-warning{{designated initializers are a C99 feature}} \
More information about the cfe-commits
mailing list