public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/35548 (dangling reference with ?:)
@ 2008-03-18  4:04 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2008-03-18  4:04 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

DR391 requires us to bind references directly to temporaries when 
appropriate, but we still need to respect LOOKUP_NO_TEMP_BIND.

Tested x86_64-pc-linux-gnu, applied to trunk and 4.3.


[-- Attachment #2: 35548.patch --]
[-- Type: text/x-patch, Size: 1484 bytes --]

2008-03-17  Jason Merrill  <jason@redhat.com>

	PR c++/35548
	* call.c (reference_binding): Check LOOKUP_NO_TEMP_BIND when binding
	a temp directly to a reference as per DR391.

Index: cp/call.c
===================================================================
*** cp/call.c	(revision 132953)
--- cp/call.c	(working copy)
*************** reference_binding (tree rto, tree rfrom,
*** 1145,1151 ****
       const and rvalue references to rvalues of compatible class type. */
    if (compatible_p
        && (lvalue_p
! 	  || ((CP_TYPE_CONST_NON_VOLATILE_P(to) || TYPE_REF_IS_RVALUE (rto))
  	      && CLASS_TYPE_P (from))))
      {
        /* [dcl.init.ref]
--- 1145,1152 ----
       const and rvalue references to rvalues of compatible class type. */
    if (compatible_p
        && (lvalue_p
! 	  || (!(flags & LOOKUP_NO_TEMP_BIND)
! 	      && (CP_TYPE_CONST_NON_VOLATILE_P(to) || TYPE_REF_IS_RVALUE (rto))
  	      && CLASS_TYPE_P (from))))
      {
        /* [dcl.init.ref]
Index: testsuite/g++.dg/init/ref16.C
===================================================================
*** testsuite/g++.dg/init/ref16.C	(revision 0)
--- testsuite/g++.dg/init/ref16.C	(revision 0)
***************
*** 0 ****
--- 1,23 ----
+ // PR c++/35548
+ // { dg-do run }
+ 
+ int c;
+ struct A
+ {
+   A() { ++c; }
+   A(const A&) { ++c; }
+   ~A() { --c; }
+ };
+ 
+ A f()
+ {
+   return A();
+ }
+ 
+ int i;
+ const A* ap;
+ int main()
+ {
+   const A& ar = i ? *ap : f();
+   return (c == 0);
+ }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-18  2:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-18  4:04 C++ PATCH for c++/35548 (dangling reference with ?:) Jason Merrill

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).