This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80228] New: inconsistent handling of ctor initialization of flexible array members
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 27 Mar 2017 23:06:42 +0000
- Subject: [Bug c++/80228] New: inconsistent handling of ctor initialization of flexible array members
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80228
Bug ID: 80228
Summary: inconsistent handling of ctor initialization of
flexible array members
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
G++ is inconsistent in diagnosing equivalent forms of initialization of
flexible array members. The following test case shows that of the four kinds
of initialization it only rejects one. The other three are accepted. Of those
three, only two initializers are diagnosed with -Wpedantic. The one in struct
D, i.e., the initialization of D::a3, is accepted without a warning. As
discussed in bug 69338, GCC also emits incorrect code for the initializers.
GCC should treat equivalent forms of initialization consistently: either it
should accept them all (possibly diagnosing them with a warning, ideally one
distinct from -Wpedantic), or it should reject them all.
$ cat z.C && gcc -S -Wall -Wextra -Wpedantic z.C
struct A { int n, a[]; };
struct B
{
int n = 3;
int a1[] = { 2, 1, 0 }; // rejected (see pr72775)
} b;
struct C
{
A a2 = { 3, { 2, 1, 0 } }; // accepted
} c;
struct D
{
int n, a3[];
D ():
n (3),
a3 {2, 1, 0} { } // silently accepted
} d;
struct E
{
A a4;
E ():
a4 {3, { 2, 1, 0 } } { } // accepted
} e;
z.C:1:21: warning: ISO C++ forbids flexible array member ‘a’ [-Wpedantic]
struct A { int n, a[]; };
^
z.C:6:24: warning: ISO C++ forbids flexible array member ‘a1’ [-Wpedantic]
int a1[] = { 2, 1, 0 }; // rejected (see pr 72775)
^
z.C:6:24: error: initializer for flexible array member ‘int B::a1 []’
z.C:11:27: warning: invalid use of ‘struct A’ with a flexible array member in
‘struct C’ [-Wpedantic]
A a2 = { 3, { 2, 1, 0 } }; // accepted
^
z.C:1:21: note: array member ‘int A::a []’ declared here
struct A { int n, a[]; };
^
z.C:11:27: warning: initialization of a flexible array member [-Wpedantic]
A a2 = { 3, { 2, 1, 0 } }; // accepted
^
z.C:16:13: warning: ISO C++ forbids flexible array member ‘a3’ [-Wpedantic]
int n, a3[];
^
z.C:25:5: warning: invalid use of ‘struct A’ with a flexible array member in
‘struct E’ [-Wpedantic]
A a4;
^~
z.C:1:21: note: array member ‘int A::a []’ declared here
struct A { int n, a[]; };
^
z.C: In constructor ‘E::E()’:
z.C:28:24: warning: initialization of a flexible array member [-Wpedantic]
a4 {3, { 2, 1, 0 } } { } // accepted
^