[Bug c++/68613] New: initializer-string for array of chars is too long error on flexible array member
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Nov 30 02:26:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68613
Bug ID: 68613
Summary: initializer-string for array of chars is too long
error on flexible array member
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
G++ (but not gcc) rejects the following valid program that relies on the GCC
extension to statically initialize a struct object with a flexible array
member. Since flexible array members are accepted in C++ mode for
compatibility with C and with GCC, and since GCC accepts such initialization
(warning only with -Wpedantic), it seems that the program below should be
accepted by g++ even without -fpermissive (and be diagnosed with -Wpedantic).
$ cat t.cpp && /build/gcc-trunk-svn/gcc/xg++ -B /build/gcc-trunk-svn/gcc -S
-Wall -Wextra -Wpedantic t.cpp
struct A {
int n;
char a[];
};
#define A(str) sizeof str, str
struct A a = { A ("abc") };
t.cpp:3:12: warning: ISO C++ forbids zero-size array ‘a’ [-Wpedantic]
char a[];
^
t.cpp:8:26: error: initializer-string for array of chars is too long
[-fpermissive]
struct A a = { A ("abc") };
^
In C mode:
$ /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra
-Wpedantic -xc t.cpp
t.cpp:8:19: warning: initialization of a flexible array member [-Wpedantic]
struct A a = { A ("abc") };
^
t.cpp:6:28: note: in definition of macro ‘A’
#define A(str) sizeof str, str
^~~
t.cpp:8:19: note: (near initialization for ‘a.a’)
struct A a = { A ("abc") };
^
t.cpp:6:28: note: in definition of macro ‘A’
#define A(str) sizeof str, str
^~~
More information about the Gcc-bugs
mailing list