public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier)
@ 2014-06-18 22:12 Jason Merrill
  2014-06-19  9:32 ` Jason Merrill
  2014-06-19 11:29 ` Marc Glisse
  0 siblings, 2 replies; 5+ messages in thread
From: Jason Merrill @ 2014-06-18 22:12 UTC (permalink / raw)
  To: gcc-patches List

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

We were treating a const & member function like a normal const 
reference, and binding an rvalue object argument to it.  But it doesn't 
work that way.

Tested x86_64-pc-linux-gnu, applying to trunk.

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

commit 20a165532a9b0b0dada391716a1fb781af3ec005
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jun 18 22:56:25 2014 +0200

    	PR c++/59296
    	* call.c (add_function_candidate): Set LOOKUP_NO_RVAL_BIND for
    	ref-qualifier handling.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1d4c4f9..b4adf36 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -2025,6 +2025,8 @@ add_function_candidate (struct z_candidate **candidates,
 		     object parameter has reference type.  */
 		  bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
 		  parmtype = cp_build_reference_type (parmtype, rv);
+		  /* Don't bind an rvalue to a const lvalue ref-qualifier.  */
+		  lflags |= LOOKUP_NO_RVAL_BIND;
 		}
 	      else
 		{
diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-qual15.C b/gcc/testsuite/g++.dg/cpp0x/ref-qual15.C
new file mode 100644
index 0000000..ca333c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/ref-qual15.C
@@ -0,0 +1,13 @@
+// PR c++/59296
+// { dg-do compile { target c++11 } }
+
+struct Type
+{
+  void get() const& { }
+  void get() const&& { }
+};
+
+int main()
+{
+  Type{}.get();
+}

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

* Re: C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier)
  2014-06-18 22:12 C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier) Jason Merrill
@ 2014-06-19  9:32 ` Jason Merrill
  2014-06-19 11:29 ` Marc Glisse
  1 sibling, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2014-06-19  9:32 UTC (permalink / raw)
  To: gcc-patches List

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

On 06/19/2014 12:12 AM, Jason Merrill wrote:
> We were treating a const & member function like a normal const
> reference, and binding an rvalue object argument to it.  But it doesn't
> work that way.

In 4.9 we also need to set LOOKUP_NO_TEMP_BIND.




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

commit 48ca9803695872d984b0f4efa56f7f58987d0928
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Jun 18 22:13:51 2014 +0000

    	PR c++/59296
    	* call.c (add_function_candidate): Set LOOKUP_NO_RVAL_BIND
    	|LOOKUP_NO_TEMP_BIND for ref-qualifier handling.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2c3d4ac..fc65b97 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1999,6 +1999,9 @@ add_function_candidate (struct z_candidate **candidates,
 		     object parameter has reference type.  */
 		  bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
 		  parmtype = cp_build_reference_type (parmtype, rv);
+		  /* Don't bind an rvalue to a const lvalue ref-qualifier.  */
+		  if (!rv)
+		    lflags |= LOOKUP_NO_RVAL_BIND|LOOKUP_NO_TEMP_BIND;
 		}
 	      else
 		{
diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-qual15.C b/gcc/testsuite/g++.dg/cpp0x/ref-qual15.C
new file mode 100644
index 0000000..ca333c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/ref-qual15.C
@@ -0,0 +1,13 @@
+// PR c++/59296
+// { dg-do compile { target c++11 } }
+
+struct Type
+{
+  void get() const& { }
+  void get() const&& { }
+};
+
+int main()
+{
+  Type{}.get();
+}

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

* Re: C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier)
  2014-06-18 22:12 C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier) Jason Merrill
  2014-06-19  9:32 ` Jason Merrill
@ 2014-06-19 11:29 ` Marc Glisse
  2014-06-20 13:12   ` Jason Merrill
  1 sibling, 1 reply; 5+ messages in thread
From: Marc Glisse @ 2014-06-19 11:29 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Thu, 19 Jun 2014, Jason Merrill wrote:

> We were treating a const & member function like a normal const reference, and 
> binding an rvalue object argument to it.  But it doesn't work that way.

That looks weird to me. The const&& version is a better match than the 
const&, so we should pick that one in overload resolution, but if we 
remove the const&& version, the other one seems valid to me, we shouldn't 
reject this program:

struct Type
{
   void get() const& { }
};

int main()
{
   Type{}.get();
}

At least both clang and intel accept it, and I hope the standard didn't 
make it behave differently from regular function calls.

-- 
Marc Glisse

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

* Re: C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier)
  2014-06-19 11:29 ` Marc Glisse
@ 2014-06-20 13:12   ` Jason Merrill
  2014-06-20 18:28     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2014-06-20 13:12 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches List

On 06/19/2014 01:29 PM, Marc Glisse wrote:
> That looks weird to me. The const&& version is a better match than the
> const&, so we should pick that one in overload resolution, but if we
> remove the const&& version, the other one seems valid to me

Hmm, you're right, I was confused.

Jason



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

* Re: C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier)
  2014-06-20 13:12   ` Jason Merrill
@ 2014-06-20 18:28     ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2014-06-20 18:28 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches List

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

On 06/20/2014 03:11 PM, Jason Merrill wrote:
> On 06/19/2014 01:29 PM, Marc Glisse wrote:
>> That looks weird to me. The const&& version is a better match than the
>> const&, so we should pick that one in overload resolution, but if we
>> remove the const&& version, the other one seems valid to me
>
> Hmm, you're right, I was confused.

Here's a patch that fixes this properly.

Tested x86_64-pc-linux-gnu, applying to trunk.



[-- Attachment #2: 59296-3.patch --]
[-- Type: text/x-patch, Size: 1805 bytes --]

commit cc1e903c60c452ad7b618f6a9ff25ae85741424e
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 20 14:51:21 2014 +0200

    	PR c++/59296
    	* call.c (add_function_candidate): Avoid special 'this' handling
    	if we have a ref-qualifier.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index da91433..4847c3a 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -2025,9 +2025,9 @@ add_function_candidate (struct z_candidate **candidates,
 		     object parameter has reference type.  */
 		  bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
 		  parmtype = cp_build_reference_type (parmtype, rv);
-		  /* Don't bind an rvalue to a const lvalue ref-qualifier.  */
-		  if (!rv)
-		    lflags |= LOOKUP_NO_RVAL_BIND|LOOKUP_NO_TEMP_BIND;
+		  /* The special handling of 'this' conversions in compare_ics
+		     does not apply if there is a ref-qualifier.  */
+		  is_this = false;
 		}
 	      else
 		{
@@ -8597,10 +8597,11 @@ compare_ics (conversion *ics1, conversion *ics2)
   /* [over.ics.rank]
 
      --S1 and S2 are reference bindings (_dcl.init.ref_) and neither refers
-     to an implicit object parameter, and either S1 binds an lvalue reference
-     to an lvalue and S2 binds an rvalue reference or S1 binds an rvalue
-     reference to an rvalue and S2 binds an lvalue reference
-     (C++0x draft standard, 13.3.3.2)
+     to an implicit object parameter of a non-static member function
+     declared without a ref-qualifier, and either S1 binds an lvalue
+     reference to an lvalue and S2 binds an rvalue reference or S1 binds an
+     rvalue reference to an rvalue and S2 binds an lvalue reference (C++0x
+     draft standard, 13.3.3.2)
 
      --S1 and S2 are reference bindings (_dcl.init.ref_), and the
      types to which the references refer are the same type except for

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

end of thread, other threads:[~2014-06-20 18:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-18 22:12 C++ PATCH for c++/59296 (rvalue object and lvalue ref-qualifier) Jason Merrill
2014-06-19  9:32 ` Jason Merrill
2014-06-19 11:29 ` Marc Glisse
2014-06-20 13:12   ` Jason Merrill
2014-06-20 18:28     ` 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).