This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53220] [4.7/4.8 Regression] g++ mis-compiles compound literals
- From: "jason at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 07 May 2012 17:44:52 +0000
- Subject: [Bug c++/53220] [4.7/4.8 Regression] g++ mis-compiles compound literals
- Auto-submitted: auto-generated
- References: <bug-53220-4@http.gcc.gnu.org/bugzilla/>
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.