http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53220

--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> 2012-05-22 
17:41:45 UTC ---
I checked the behavior of clang and icc with the following testcase:

extern "C" int printf (const char *,...);

struct A
{
  int i;
  ~A() { printf ("~A()\n"); }
};

int main()
{
  for (A *p = (A[]){ 1, 2, 3, 0}; p->i; ++p) {
    printf("%d\n", p->i);
  }
  return 0;
}

Both compilers match G++ behavior and destroy all the elements of the array
before the loop begins; the only difference is that recent G++ is more
aggressive about optimizing based on the knowledge that the array is no longer
alive.

So yes, what remains for this bug is to complain about undefined behavior due
to accessing the value of an object after its lifetime has ended.

Reply via email to