From 0333296d142d45bf2723635848928815b7491f91 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 29 Jul 2010 14:29:34 +0000 Subject: [PATCH] Reword the empty struct/union warning in C to note that such structs and unions have size 0 in C, size 1 in C++. Put this warning under -Wc++-compat. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109748 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 2 +- include/clang/Basic/DiagnosticParseKinds.td | 5 +++-- lib/Parse/ParseDecl.cpp | 4 ++-- test/Sema/array-init.c | 6 ++++-- test/Sema/compound-literal.c | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 205dc73915..b8b683cb5a 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -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">; diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index ca761f9bf5..e238a8ebf1 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -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; 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">; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 62ef3ec017..6f65640d60 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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 FieldDecls; diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c index f93b0878fd..c042943516 100644 --- a/test/Sema/array-init.c +++ b/test/Sema/array-init.c @@ -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; diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index 08c30b3c87..aade4641ac 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -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; -- 2.40.0