VLAs as C++ fields - bug or feature?
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Sat Mar 25 10:53:00 GMT 2000
Currently, we have a number of pending bug reports about crashes in
find_function_data, which all seem to originate from code like this:
struct X{
static int l;
char x[l];
int y;
void foo()
{
y=4;
}
};
int main()
{
X *x = new X;
x->foo();
}
Clearly, the author of this code intended to make X::l a
constant. cc1plus crashes when trying to find out the offset of y in
an X object; it somehow thinks we have a nested function here...
Interesting enough, if foo is only declared, not defined, g++ will
generate code that looks meaningful on first inspection, i.e. it will
try to compute the size of X at runtime.
Please let me know that this is not an extension and that the correct
behaviour would be to outright reject this code. Note that it gives a
VLA warning with -pedantic. Maybe I'm a pedant then, too :-)
Regards,
Martin
More information about the Gcc
mailing list