[cfe-commits] r66308 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDecl.cpp test/Sema/struct-decl.c

Douglas Gregor dgregor at apple.com
Fri Mar 6 15:41:27 PST 2009


Author: dgregor
Date: Fri Mar  6 17:41:27 2009
New Revision: 66308

URL: http://llvm.org/viewvc/llvm-project?rev=66308&view=rev
Log:
Downgrade complaints about the use of variable-sized types within a
struct to an extension warning to match the behavior of GNU C, which
addresses the Sema part of PR3671.


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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=66308&r1=66307&r2=66308&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Fri Mar  6 17:41:27 2009
@@ -774,8 +774,9 @@
      "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,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66308&r1=66307&r2=66308&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar  6 17:41:27 2009
@@ -3525,19 +3525,17 @@
           // 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);
         }
       }
     }

Modified: cfe/trunk/test/Sema/struct-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/struct-decl.c?rev=66308&r1=66307&r2=66308&view=diff

==============================================================================
--- cfe/trunk/test/Sema/struct-decl.c (original)
+++ cfe/trunk/test/Sema/struct-decl.c Fri Mar  6 17:41:27 2009
@@ -23,13 +23,13 @@
         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;
 };
 





More information about the cfe-commits mailing list