]> granicus.if.org Git - clang/commitdiff
Reword the empty struct/union warning in C to note that such structs and unions have...
authorDouglas Gregor <dgregor@apple.com>
Thu, 29 Jul 2010 14:29:34 +0000 (14:29 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 29 Jul 2010 14:29:34 +0000 (14:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109748 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
test/Sema/array-init.c
test/Sema/compound-literal.c

index 205dc739159311fc5be5a4ae00aca2d11b49603e..b8b683cb5ac7562396e1bf405bda7b811bc47d78 100644 (file)
@@ -25,7 +25,7 @@ def AmbigMemberTemplate : DiagGroup<"ambiguous-member-template">;
 def : DiagGroup<"attributes">;
 def : DiagGroup<"bad-function-cast">;
 def BoolConversions : DiagGroup<"bool-conversions">;
-def : DiagGroup<"c++-compat">;
+def CXXCompat: DiagGroup<"c++-compat">;
 def : DiagGroup<"cast-align">;
 def : DiagGroup<"cast-qual">;
 def : DiagGroup<"char-align">;
index ca761f9bf5e9b9d7bed8283ff295cba780a5847d..e238a8ebf15951c329aa046d23cb666e1d7f4b1c 100644 (file)
@@ -35,8 +35,9 @@ def ext_integer_complex : Extension<
   "complex integer types are an extension">;
 def ext_thread_before : Extension<"'__thread' before 'static'">;
 
-def ext_empty_struct_union_enum : Extension<"use of empty %0 extension">;
-
+def ext_empty_struct_union : Extension<"empty %select{struct|union}0 "
+  "(accepted as an extension) has size 0 in C, size 1 in C++">, 
+  InGroup<CXXCompat>;
 def error_empty_enum : Error<"use of empty enum">;
 def err_invalid_sign_spec : Error<"'%0' cannot be signed or unsigned">;
 def err_invalid_short_spec : Error<"'short %0' is invalid">;
index 62ef3ec0179bbce2cb4bb319458672aebf5ee616..6f65640d605e213cc9a5b74ed0469c5e51e7f8cc 100644 (file)
@@ -1782,8 +1782,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
   // Empty structs are an extension in C (C99 6.7.2.1p7), but are allowed in
   // C++.
   if (Tok.is(tok::r_brace) && !getLang().CPlusPlus)
-    Diag(Tok, diag::ext_empty_struct_union_enum)
-      << DeclSpec::getSpecifierName((DeclSpec::TST)TagType);
+    Diag(Tok, diag::ext_empty_struct_union)
+      << (TagType == TST_union);
 
   llvm::SmallVector<DeclPtrTy, 32> FieldDecls;
 
index f93b0878fd3f1ad24fad19b0d735ccc246697381..c042943516dd8c816addba27318c1f7ac5857c2d 100644 (file)
@@ -218,7 +218,8 @@ void varArray() {
 }
 
 // PR2151
-void emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct extension}} expected-error{{initializer for aggregate with no elements}}
+void emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}} \
+// expected-error{{initializer for aggregate with no elements}}
 
 void noNamedInit() {
   struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
@@ -241,7 +242,8 @@ struct soft_segment_descriptor gdt_segs[] = {
 };
 
 static void sppp_ipv6cp_up();
-const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct extension}} expected-warning{{excess elements in struct initializer}}
+const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}} \
+// expected-warning{{excess elements in struct initializer}}
 
 struct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a GNU extension in C}}
 typedef struct _Matrix Matrix;
index 08c30b3c876decacb62bd99811996db5b66c8832..aade4641ace08ad1befb76e80d72eedaafdf7c1c 100644 (file)
@@ -11,7 +11,7 @@ static int x = (int){1};
 static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}}
 static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}}
 
-typedef struct { } cache_t; // -expected-warning{{use of empty struct extension}}
+typedef struct { } cache_t; // -expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}}
 static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}}
 
 typedef struct Test {int a;int b;} Test;