diff options
author | Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> | 2015-06-03 15:10:44 +0000 |
---|---|---|
committer | Prathamesh Kulkarni <prathamesh3492@gcc.gnu.org> | 2015-06-03 15:10:44 +0000 |
commit | bc51ace3600b5c9b5dcad09f16858e5727866e27 (patch) | |
tree | 3096135066177486fe57c67c799c10f0bcb121e2 /gcc/c | |
parent | 80a4fe78bf071c07a71f640bd861193b85c27138 (diff) | |
download | gcc-bc51ace3600b5c9b5dcad09f16858e5727866e27.zip gcc-bc51ace3600b5c9b5dcad09f16858e5727866e27.tar.gz gcc-bc51ace3600b5c9b5dcad09f16858e5727866e27.tar.bz2 |
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
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 15 |
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index a4bf620..69344bb 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +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> * c-decl.c (start_function): Call plugin before parsing. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index efdf902..efb978b 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 (); |