aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2024-05-06 16:26:19 +0000
committerQing Zhao <qing.zhao@oracle.com>2024-05-06 18:32:58 +0000
commitf27fc59d9f7c735d200fda647a487850144b10eb (patch)
treee789eab17c762caab752fd74961f696f7b660948 /gcc/cp
parentadb1c8a0f167c3a1f7593d75f5a10eb07a5d741a (diff)
downloadgcc-f27fc59d9f7c735d200fda647a487850144b10eb.zip
gcc-f27fc59d9f7c735d200fda647a487850144b10eb.tar.gz
gcc-f27fc59d9f7c735d200fda647a487850144b10eb.tar.bz2
C and C++ FE changes to support flexible array members in unions and alone in structures. Adjust testcases for flexible array member in union and alone in structure extension.
PR c/53548 gcc/c/ChangeLog: PR c/53548 * c-decl.cc (finish_struct): Change errors to pedwarns for the cases flexible array members in union or alone in structures. gcc/cp/ChangeLog: PR c/53548 * class.cc (diagnose_flexarrays): Change error to pdewarn for the case flexible array members alone in structures. * decl.cc (grokdeclarator): Change error to pdewarn for the case flexible array members in unions. gcc/ChangeLog: PR c/53548 * stor-layout.cc (place_union_field): Use zero sizes for flexible array member fields. gcc/testsuite/ChangeLog: PR c/53548 * c-c++-common/builtin-clear-padding-3.c: Adjust testcase. * g++.dg/ext/flexary12.C: Likewise. * g++.dg/ext/flexary19.C: Likewise. * g++.dg/ext/flexary2.C: Likewise. * g++.dg/ext/flexary3.C: Likewise. * g++.dg/ext/flexary36.C: Likewise. * g++.dg/ext/flexary4.C: Likewise. * g++.dg/ext/flexary5.C: Likewise. * g++.dg/ext/flexary8.C: Likewise. * g++.dg/torture/pr64280.C: Likewise. * gcc.dg/20050620-1.c: Likewise. * gcc.dg/940510-1.c: Likewise.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/class.cc11
-rw-r--r--gcc/cp/decl.cc7
2 files changed, 11 insertions, 7 deletions
diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 5ef7c71..0ce361e 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -7624,6 +7624,7 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem)
bool diagd = false;
const char *msg = 0;
+ const char *msg_fam = 0;
if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
{
@@ -7649,15 +7650,19 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem)
if (fmem->after[0])
msg = G_("flexible array member %qD not at end of %q#T");
else if (!fmem->first)
- msg = G_("flexible array member %qD in an otherwise empty %q#T");
+ msg_fam = G_("flexible array member %qD in an otherwise"
+ " empty %q#T is a GCC extension");
- if (msg)
+ if (msg || msg_fam)
{
location_t loc = DECL_SOURCE_LOCATION (fmem->array);
diagd = true;
auto_diagnostic_group d;
- error_at (loc, msg, fmem->array, t);
+ if (msg)
+ error_at (loc, msg, fmem->array, t);
+ else
+ pedwarn (loc, OPT_Wpedantic, msg_fam, fmem->array, t);
/* In the unlikely event that the member following the flexible
array member is declared in a different class, or the member
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 71e4c2b..e8622e2 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -14582,10 +14582,9 @@ grokdeclarator (const cp_declarator *declarator,
if (ctype
&& (TREE_CODE (ctype) == UNION_TYPE
|| TREE_CODE (ctype) == QUAL_UNION_TYPE))
- {
- error_at (id_loc, "flexible array member in union");
- type = error_mark_node;
- }
+ pedwarn (id_loc, OPT_Wpedantic,
+ "flexible array member in union is a GCC extension");
+
else
{
/* Array is a flexible member. */