This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

VLAs as C++ fields - bug or feature?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]