summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.def5
-rw-r--r--clang/lib/Sema/SemaDecl.cpp20
-rw-r--r--clang/test/Sema/struct-decl.c4
3 files changed, 14 insertions, 15 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.def b/clang/include/clang/Basic/DiagnosticSemaKinds.def
index ce40a9bfab9..27708236d18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.def
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.def
@@ -774,8 +774,9 @@ DIAG(err_field_declared_as_function, ERROR,
"field %0 declared as a function")
DIAG(err_field_incomplete, ERROR,
"field has incomplete type %0")
-DIAG(err_variable_sized_type_in_struct, ERROR,
- "variable sized type %0 must be at end of struct or class")
+DIAG(ext_variable_sized_type_in_struct, EXTWARN,
+ "variable sized type %0 not at the end of a struct or class is a "
+ "GNU extension")
DIAG(err_flexible_array_empty_struct, ERROR,
"flexible array %0 not allowed in otherwise empty struct")
DIAG(ext_flexible_array_in_struct, EXTENSION,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5e7ce52ee87..e902cbe135c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3525,19 +3525,17 @@ void Sema::ActOnFields(Scope* S,
// If this is a struct/class and this is not the last element, reject
// it. Note that GCC supports variable sized arrays in the middle of
// structures.
- if (i != NumFields-1) {
- Diag(FD->getLocation(), diag::err_variable_sized_type_in_struct)
+ if (i != NumFields-1)
+ Diag(FD->getLocation(), diag::ext_variable_sized_type_in_struct)
<< FD->getDeclName();
- FD->setInvalidDecl();
- EnclosingDecl->setInvalidDecl();
- continue;
+ else {
+ // We support flexible arrays at the end of structs in
+ // other structs as an extension.
+ Diag(FD->getLocation(), diag::ext_flexible_array_in_struct)
+ << FD->getDeclName();
+ if (Record)
+ Record->setHasFlexibleArrayMember(true);
}
- // We support flexible arrays at the end of structs in other structs
- // as an extension.
- Diag(FD->getLocation(), diag::ext_flexible_array_in_struct)
- << FD->getDeclName();
- if (Record)
- Record->setHasFlexibleArrayMember(true);
}
}
}
diff --git a/clang/test/Sema/struct-decl.c b/clang/test/Sema/struct-decl.c
index aa2d3b6342b..e71a0b2b0c4 100644
--- a/clang/test/Sema/struct-decl.c
+++ b/clang/test/Sema/struct-decl.c
@@ -23,13 +23,13 @@ int foo() {
return f->v + f[0].v;
}
-// PR3642
+// PR3642, PR3671
struct pppoe_tag {
short tag_type;
char tag_data[];
};
struct datatag {
- struct pppoe_tag hdr; //expected-error{{variable sized type 'hdr' must be at end of struct}}
+ struct pppoe_tag hdr; //expected-warning{{variable sized type 'hdr' not at the end of a struct or class is a GNU extension}}
char data;
};
OpenPOWER on IntegriCloud