From: Prathamesh Kulkarni Date: Wed, 3 Jun 2015 15:10:44 +0000 (+0000) Subject: c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bc51ace3600b5c9b5dcad09f16858e5727866e27;p=gcc.git c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc. 2015-06-03 Prathamesh Kulkarni c/ * c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc. Warn for empty struct. (finish_struct): Pass TREE_CODE(t) and loc to warn_cxx_compat_finish_struct. testsuite/ * gcc.dg/Wcxx-compat-22.c: New testcase. * c-c++-common/Wsizeof-pointer-memaccess1.c: Pass -Wno-c++-compat. * c-c++-common/Wsizeof-pointer-memaccess2.c: Likewise. * c-c++-common/pr58346-1.c: Likewise. * c-c++-common/transparent-union-1.c: Likewise. From-SVN: r224083 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index a4bf6203ccf..69344bb7bb1 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-06-03 Prathamesh Kulkarni + + * c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc. + Warn for empty struct. + (finish_struct): Pass TREE_CODE(t) and loc to warn_cxx_compat_finish_struct. + 2015-06-02 Andres Tiraboschi * c-decl.c (start_function): Call plugin before parsing. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index efdf9028596..efb978b97e1 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -7525,12 +7525,23 @@ detect_field_duplicates (tree fieldlist) /* Finish up struct info used by -Wc++-compat. */ static void -warn_cxx_compat_finish_struct (tree fieldlist) +warn_cxx_compat_finish_struct (tree fieldlist, enum tree_code code, + location_t record_loc) { unsigned int ix; tree x; struct c_binding *b; + if (fieldlist == NULL_TREE) + { + if (code == RECORD_TYPE) + warning_at (record_loc, OPT_Wc___compat, + "empty struct has size 0 in C, size 1 in C++"); + else + warning_at (record_loc, OPT_Wc___compat, + "empty union has size 0 in C, size 1 in C++"); + } + /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in the current struct. We do this now at the end of the struct because the flag is used to issue visibility warnings, and we @@ -7863,7 +7874,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t))); if (warn_cxx_compat) - warn_cxx_compat_finish_struct (fieldlist); + warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc); struct_parse_info->struct_types.release (); struct_parse_info->fields.release (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 13e7ecb4a14..efd859b8ef5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2015-06-03 Prathamesh Kulkarni + + * gcc.dg/Wcxx-compat-22.c: New testcase. + * c-c++-common/Wsizeof-pointer-memaccess1.c: Pass -Wno-c++-compat. + * c-c++-common/Wsizeof-pointer-memaccess2.c: Likewise. + * c-c++-common/pr58346-1.c: Likewise. + * c-c++-common/transparent-union-1.c: Likewise. + 2015-06-02 Andres Tiraboschi * g++.dg/plugin/plugin.exp: Add def-plugin-test.C. diff --git a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess1.c b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess1.c index 8e829d61ae0..27c5da426bd 100644 --- a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess1.c +++ b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess1.c @@ -1,6 +1,7 @@ /* Test -Wsizeof-pointer-memaccess warnings. */ /* { dg-do compile } */ /* { dg-options "-Wall -Wno-sizeof-array-argument" } */ +/* { dg-options "-Wall -Wno-sizeof-array-argument -Wno-c++-compat" { target c } } */ typedef __SIZE_TYPE__ size_t; #ifdef __cplusplus diff --git a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c index fe17a7056ab..e067d7d44e9 100644 --- a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c +++ b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c @@ -1,6 +1,7 @@ /* Test -Wsizeof-pointer-memaccess warnings. */ /* { dg-do compile } */ /* { dg-options "-Wall -O2 -Wno-sizeof-array-argument" } */ +/* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -Wno-c++-compat" {target c} } */ #define bos(ptr) __builtin_object_size (ptr, 1) #define bos0(ptr) __builtin_object_size (ptr, 0) diff --git a/gcc/testsuite/c-c++-common/pr58346-1.c b/gcc/testsuite/c-c++-common/pr58346-1.c index 371fcf48454..70a16d12d97 100644 --- a/gcc/testsuite/c-c++-common/pr58346-1.c +++ b/gcc/testsuite/c-c++-common/pr58346-1.c @@ -1,5 +1,6 @@ /* PR c/58346 */ /* { dg-do compile } */ +/* { dg-options "-Wno-c++-compat" { target c } } */ struct U { #ifdef __cplusplus diff --git a/gcc/testsuite/c-c++-common/transparent-union-1.c b/gcc/testsuite/c-c++-common/transparent-union-1.c index 3fb6e782a14..91f2642fdbc 100644 --- a/gcc/testsuite/c-c++-common/transparent-union-1.c +++ b/gcc/testsuite/c-c++-common/transparent-union-1.c @@ -1,4 +1,5 @@ /* PR c++/51228 */ +/* { dg-options "-Wno-c++-compat" { target c } } */ typedef union {} U __attribute__((transparent_union)); /* { dg-warning "ignored" } */ diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-22.c b/gcc/testsuite/gcc.dg/Wcxx-compat-22.c new file mode 100644 index 00000000000..60b05ca93f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wcxx-compat-22.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-Wc++-compat" } */ +struct A {}; /* { dg-warning "empty struct has size 0 in C" } */ +union B {}; /* { dg-warning "empty union has size 0 in C" } */ +struct C { struct D {}; int x; }; /* { dg-warning "empty struct has size 0 in C|declaration does not declare anything" } */ +struct E { union F {}; int x; }; /* { dg-warning "empty union has size 0 in C|declaration does not declare anything" } */ +union G { union H {}; int x; }; /* { dg-warning "empty union has size 0 in C|declaration does not declare anything" } */ +union I { struct J {}; int x; }; /* { dg-warning "empty struct has size 0 in C|declaration does not declare anything" } */