[Bug c++/68478] New: flexible array members have complete type

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Nov 21 23:47:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68478

            Bug ID: 68478
           Summary: flexible array members have complete type
           Product: gcc
           Version: 6.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++ accepts definitions of C flexible array members as an extension.  However,
since C specifies that a flexible array member has an incomplete type, such a
member is not a valid operand in expressions that require an object to have a
complete type.  An example is the sizeof expression.  Since flexible array
members are provided for compatibility with C, they should be subject to the
same requirements and restrictions.

$ cat z.cpp && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -Wall
-Wextra -Wpedantic -xc++ z.cpp
struct S {
    int n;
    int a[];
} s;

extern int a[];

enum E {
    e = sizeof s.a,   // rejected in C, accepted in C++
    f = sizeof a      // rejected in both C and C++
};

z.cpp:3:11: warning: ISO C++ forbids zero-size array ‘a’ [-Wpedantic]
     int a[];
           ^

z.cpp:10:16: error: invalid application of ‘sizeof’ to incomplete type ‘int []’
     f = sizeof a      // rejected in both C and C++
                ^


More information about the Gcc-bugs mailing list