]> granicus.if.org Git - clang/commitdiff
Downgrade complaints about the use of variable-sized types within a
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 Mar 2009 23:41:27 +0000 (23:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 Mar 2009 23:41:27 +0000 (23:41 +0000)
struct to an extension warning to match the behavior of GNU C, which
addresses the Sema part of PR3671.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66308 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.def
lib/Sema/SemaDecl.cpp
test/Sema/struct-decl.c

index ce40a9bfab9b8cce1d606229e65cc1bcf6d8f2e1..27708236d1831f92dda916ac6e1a93154e4f64f9 100644 (file)
@@ -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,
index 5e7ce52ee876f493c5b120d5814032e00b8562a7..e902cbe135c6d733473d1fb292e287350a181cac 100644 (file)
@@ -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);
         }
       }
     }
index aa2d3b6342b696c8cbe0864661c184d407882059..e71a0b2b0c4f7124eb52e37acba813eee25d3d6b 100644 (file)
@@ -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;
 };