Commit bc51ace3 by Prathamesh Kulkarni Committed by Prathamesh Kulkarni

c-decl.c (warn_cxx_compat_finish_struct): New parameters code, record_loc.

2015-06-03  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

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
parent 80a4fe78
2015-06-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
* 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 <andres.tiraboschi@tallertechnologies.com> 2015-06-02 Andres Tiraboschi <andres.tiraboschi@tallertechnologies.com>
* c-decl.c (start_function): Call plugin before parsing. * c-decl.c (start_function): Call plugin before parsing.
......
...@@ -7525,12 +7525,23 @@ detect_field_duplicates (tree fieldlist) ...@@ -7525,12 +7525,23 @@ detect_field_duplicates (tree fieldlist)
/* Finish up struct info used by -Wc++-compat. */ /* Finish up struct info used by -Wc++-compat. */
static void 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; unsigned int ix;
tree x; tree x;
struct c_binding *b; 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 /* 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 the current struct. We do this now at the end of the struct
because the flag is used to issue visibility warnings, and we 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, ...@@ -7863,7 +7874,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t))); DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t)));
if (warn_cxx_compat) 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->struct_types.release ();
struct_parse_info->fields.release (); struct_parse_info->fields.release ();
......
2015-06-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
* 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 <andres.tiraboschi@tallertechnologies.com> 2015-06-02 Andres Tiraboschi <andres.tiraboschi@tallertechnologies.com>
* g++.dg/plugin/plugin.exp: Add def-plugin-test.C. * g++.dg/plugin/plugin.exp: Add def-plugin-test.C.
......
/* Test -Wsizeof-pointer-memaccess warnings. */ /* Test -Wsizeof-pointer-memaccess warnings. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-Wall -Wno-sizeof-array-argument" } */ /* { dg-options "-Wall -Wno-sizeof-array-argument" } */
/* { dg-options "-Wall -Wno-sizeof-array-argument -Wno-c++-compat" { target c } } */
typedef __SIZE_TYPE__ size_t; typedef __SIZE_TYPE__ size_t;
#ifdef __cplusplus #ifdef __cplusplus
......
/* Test -Wsizeof-pointer-memaccess warnings. */ /* Test -Wsizeof-pointer-memaccess warnings. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-Wall -O2 -Wno-sizeof-array-argument" } */ /* { 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 bos(ptr) __builtin_object_size (ptr, 1)
#define bos0(ptr) __builtin_object_size (ptr, 0) #define bos0(ptr) __builtin_object_size (ptr, 0)
......
/* PR c/58346 */ /* PR c/58346 */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-Wno-c++-compat" { target c } } */
struct U { struct U {
#ifdef __cplusplus #ifdef __cplusplus
......
/* PR c++/51228 */ /* PR c++/51228 */
/* { dg-options "-Wno-c++-compat" { target c } } */
typedef union {} U __attribute__((transparent_union)); /* { dg-warning "ignored" } */ typedef union {} U __attribute__((transparent_union)); /* { dg-warning "ignored" } */
......
/* { 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" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment