public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [4.6 branch] Issue with C++ references.
@ 2011-10-18 15:20 Yvan ROUX
  2011-10-19  5:46 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Yvan ROUX @ 2011-10-18 15:20 UTC (permalink / raw)
  To: gcc

Hi,

I have the small program below, which check the binding of a reference :

int main() {
        const int Ci = 0;
        const int &rCi = Ci;
        if (!(&Ci == &rCi)) return 1;
        return 0;
}

If my understanding of the standard (8.5.3) is correct, the reference is
an lvalue (rCi), the initializer expression (Ci) is an lvalue and the two 
referenced types are the same => rCi is bound to Ci, my program is a
valid one. If this is not the case, the rest of this mail could be skip.
 
The program has the expected behaviour if you use a 4.5 gcc or the trunk, but
if you compile it with a 4.6 one (even with the branch's head) with -O0,
the program returns the 1 value, because rCi is not bound to Ci, but to an
anonymous temporary which cantains the value 0. 

The problem was introduced during the integration of the constexpr support,
in the cp_parser_initializer_clause function of the parser.c file, with the 
commit :
Git : ce984e5e401accb43a1c4bfee31a4743f4004118
Svn : trunk@166167

and was fixed on the trunk by the commit :
Git : 5e260adbb1f177a25a39691d3e4510d6bc3b898a
Svn : trunk@175284

In fact only the part of the commit which removes the call to 
maybe_constant_value in cp_parser_initializer_clause fixes the bug.
I'm not really sure of what I have to do in such a case :
peparing the patch or asking to backport Jason's on the 4.6 branch ?


Many Thanks

Yvan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [4.6 branch] Issue with C++ references.
  2011-10-18 15:20 [4.6 branch] Issue with C++ references Yvan ROUX
@ 2011-10-19  5:46 ` Jason Merrill
  2011-10-19 12:57   ` Yvan ROUX
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2011-10-19  5:46 UTC (permalink / raw)
  To: Yvan ROUX; +Cc: gcc

On 10/18/2011 09:57 AM, Yvan ROUX wrote:
> int main() {
>          const int Ci = 0;
>          const int&rCi = Ci;
>          if (!(&Ci ==&rCi)) return 1;
>          return 0;
> }
>
> The program has the expected behaviour if you use a 4.5 gcc or the trunk, but
> if you compile it with a 4.6 one (even with the branch's head) with -O0,
> the program returns the 1 value, because rCi is not bound to Ci, but to an
> anonymous temporary which cantains the value 0.

Eep!

> In fact only the part of the commit which removes the call to
> maybe_constant_value in cp_parser_initializer_clause fixes the bug.
> I'm not really sure of what I have to do in such a case :
> preparing the patch or asking to backport Jason's on the 4.6 branch ?

I'll backport that hunk, thanks for catching this.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [4.6 branch] Issue with C++ references.
  2011-10-19  5:46 ` Jason Merrill
@ 2011-10-19 12:57   ` Yvan ROUX
  0 siblings, 0 replies; 3+ messages in thread
From: Yvan ROUX @ 2011-10-19 12:57 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc

On Wed, Oct 19, 2011 at 06:08:15AM +0200, Jason Merrill wrote:
> I'll backport that hunk, thanks for catching this.

Great ! You're welcome Jason.

Yvan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-19  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-18 15:20 [4.6 branch] Issue with C++ references Yvan ROUX
2011-10-19  5:46 ` Jason Merrill
2011-10-19 12:57   ` Yvan ROUX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).