https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69023
Bug ID: 69023
Summary: bitset whose name is used in constant-expression
rejected
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: ---
The declaration of b1 in the test case below is rejected for what seems to be
an invalid reason. The bit-field x doesn't exist yet at the point the sizeof x
expression is seen in the constant expression. The error also seems confused:
it points that the local variable x and says its meaning is being changed but
doesn't say by what (i.e., it never points at the declaration of the
bit-field).
I'm sure this is a corner case but I think it's a bug in GCC because in the
subsequent declaration of b2, the sizeof y expression is rejected with an error
implying that GCC doesn't treat the bit-field declaration as complete at that
point.
Clang accepts the declarations of b0 and b1 and rejects the declaration of b2
with a similar error as GCC.
$ cat x.cpp && /home/msebor/build/gcc-trunk-svn/gcc/xgcc
-B/home/msebor/build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -o/dev/null
x.cpp
void foo () {
int x;
{
struct { int : sizeof x; } b0; (void)&b0;
struct { int x: sizeof x; } b1; (void)&b1;
struct { int y: sizeof y; } b2; (void)&b2;
}
}
x.cpp: In function ‘void foo()’:
x.cpp:5:32: error: declaration of ‘int foo()::<anonymous struct>::x’
[-fpermissive]
struct { int x: sizeof x; } b1; (void)&b1;
^
x.cpp:2:9: error: changes meaning of ‘x’ from ‘int x’ [-fpermissive]
int x;
^
x.cpp:6:32: error: ‘y’ was not declared in this scope
struct { int y: sizeof y; } b2; (void)&b2;
^