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: "xinliangli at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 08 May 2012 00:16:30 +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 #9 from davidxl <xinliangli at gmail dot com> 2012-05-08 00:16:30 UTC ---
c++11 defines the lifetime of a temporary -- does it match C or g++'s semantics
of compound literals or neither?
Note that without your change, the original program may also be subject to
runtime failures due to escaped life ranges of the scoped variables leading to
bad stack layout -- though such bugs are more subtle and less likely to be
triggered.
David
(In reply to comment #8)
> 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.