[Bug c++/53220] [4.7/4.8 Regression] g++ mis-compiles compound literals
jason at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon May 7 17:55:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53220
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2012-05-07 17:44:52 UTC ---
The thing is, C++11 introduces list-initialized temporaries; I could rewrite
the testcase in C++11 as
extern "C" int printf (const char *, ...);
int main()
{
typedef int AR[4];
for (int *p = AR{1,2,3,0}; *p; ++p)
{
printf ("%d\n", *p);
}
return 0;
}
so it made sense to me for compound literals to have the same semantics;
otherwise you have a difference in lifetime based on whether or not the type is
wrapped in parentheses.
I definitely agree that we need to give a diagnostic about taking the address
of a temporary here.
More information about the Gcc-bugs
mailing list