[cfe-commits] r127171 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/flexible-array-test.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Mar 7 12:04:05 PST 2011
Author: akirtzidis
Date: Mon Mar 7 14:04:04 2011
New Revision: 127171
URL: http://llvm.org/viewvc/llvm-project?rev=127171&view=rev
Log:
g++ is more permissive regarding flexible arrays.
It will accept flexible array in union and also as the sole element of a struct/class.
Fixes rdar://9065507.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/flexible-array-test.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127171&r1=127170&r2=127171&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Mar 7 14:04:04 2011
@@ -2288,12 +2288,17 @@
"%0 may not be used as an array element due to flexible array member">;
def err_flexible_array_init_nonempty : Error<
"non-empty initialization of flexible array member inside subobject">;
-def ext_flexible_array_empty_aggregate : Extension<
+def ext_flexible_array_empty_aggregate_ms : Extension<
"flexible array member %0 in otherwise empty %select{struct|class}1 "
"is a Microsoft extension">, InGroup<Microsoft>;
-def ext_flexible_array_union : Extension<
+def ext_flexible_array_union_ms : Extension<
"flexible array member %0 in a union is a Microsoft extension">,
InGroup<Microsoft>;
+def ext_flexible_array_empty_aggregate_gnu : Extension<
+ "flexible array member %0 in otherwise empty %select{struct|class}1 "
+ "is a GNU extension">, InGroup<GNU>;
+def ext_flexible_array_union_gnu : Extension<
+ "flexible array member %0 in a union is a GNU extension">, InGroup<GNU>;
def err_flexible_array_init_needs_braces : Error<
"flexible array requires brace-enclosed initializer">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127171&r1=127170&r2=127171&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 7 14:04:04 2011
@@ -7374,20 +7374,27 @@
continue;
} else if (FDTy->isIncompleteArrayType() && Record &&
((i == NumFields - 1 && !Record->isUnion()) ||
- (getLangOptions().Microsoft &&
+ ((getLangOptions().Microsoft || getLangOptions().CPlusPlus) &&
(i == NumFields - 1 || Record->isUnion())))) {
// Flexible array member.
- // Microsoft is more permissive regarding flexible array.
+ // Microsoft and g++ is more permissive regarding flexible array.
// It will accept flexible array in union and also
// as the sole element of a struct/class.
if (getLangOptions().Microsoft) {
if (Record->isUnion())
- Diag(FD->getLocation(), diag::ext_flexible_array_union)
+ Diag(FD->getLocation(), diag::ext_flexible_array_union_ms)
<< FD->getDeclName();
else if (NumFields == 1)
- Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate)
+ Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate_ms)
<< FD->getDeclName() << Record->getTagKind();
- } else if (NumNamedMembers < 1) {
+ } else if (getLangOptions().CPlusPlus) {
+ if (Record->isUnion())
+ Diag(FD->getLocation(), diag::ext_flexible_array_union_gnu)
+ << FD->getDeclName();
+ else if (NumFields == 1)
+ Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate_gnu)
+ << FD->getDeclName() << Record->getTagKind();
+ } else if (NumNamedMembers < 1) {
Diag(FD->getLocation(), diag::err_flexible_array_empty_struct)
<< FD->getDeclName();
FD->setInvalidDecl();
Modified: cfe/trunk/test/SemaCXX/flexible-array-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/flexible-array-test.cpp?rev=127171&r1=127170&r2=127171&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/flexible-array-test.cpp (original)
+++ cfe/trunk/test/SemaCXX/flexible-array-test.cpp Mon Mar 7 14:04:04 2011
@@ -51,5 +51,19 @@
union B {
int s;
- char c[]; // expected-error {{field has incomplete type 'char []'}}
+ char c[];
};
+
+namespace rdar9065507 {
+
+struct StorageBase {
+ long ref_count;
+ unsigned size;
+ unsigned capacity;
+};
+
+struct Storage : StorageBase {
+ int data[];
+};
+
+}
More information about the cfe-commits
mailing list