This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3230: False warning for 'returning reference to temporary'
- From: jason at gcc dot gnu dot org
- To: andrewp at andypo dot net, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, gdr at gcc dot gnu dot org, jason at gcc dot gnu dot org
- Date: 18 Mar 2002 14:02:21 -0000
- Subject: Re: c++/3230: False warning for 'returning reference to temporary'
- Reply-to: jason at gcc dot gnu dot org, andrewp at andypo dot net, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, gdr at gcc dot gnu dot org, jason at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: False warning for 'returning reference to temporary'
Responsible-Changed-From-To: gdr->jason
Responsible-Changed-By: jason
Responsible-Changed-When: Mon Mar 18 06:02:19 2002
Responsible-Changed-Why:
mine
State-Changed-From-To: analyzed->closed
State-Changed-By: jason
State-Changed-When: Mon Mar 18 06:02:19 2002
State-Changed-Why:
This is not a bug in the compiler. The standard (5.16) says that the result of your ?: expression is an rvalue, because the two options do not have the same type. As a result, the return value binds to that rvalue, which is a local temporary. The EDG compiler gives the same warning.
You may feel that this is a bug in the standard, and I'd be inclined to agree. But until the standard is fixed, the compiler will continue to work this way. If you'd like to submit a defect report against the standard, the place for that is comp.std.c++.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=3230