public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for core DR 2007
@ 2014-11-10  4:49 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2014-11-10  4:49 UTC (permalink / raw)
  To: gcc-patches List

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

DR 2007 points out that there's no need to do argument-dependent lookup 
for operator=, which has to be a member function.

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

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

commit 7601c0b8fb5d7093479f5587057f049bdc6cb622
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Nov 8 09:32:15 2014 -0600

    	DR 2007
    	* call.c (build_new_op_1): Don't do non-class lookup for =, -> or [].

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 31864e9..bf191ca 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -5309,6 +5309,7 @@ build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1,
 
   arg1 = prep_operand (arg1);
 
+  bool memonly = false;
   switch (code)
     {
     case NEW_EXPR:
@@ -5340,6 +5341,16 @@ build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1,
       code_orig_arg1 = TREE_CODE (TREE_TYPE (arg1));
       code_orig_arg2 = TREE_CODE (TREE_TYPE (arg2));
       break;
+
+      /* =, ->, [], () must be non-static member functions.  */
+    case MODIFY_EXPR:
+      if (code2 != NOP_EXPR)
+	break;
+    case COMPONENT_REF:
+    case ARRAY_REF:
+      memonly = true;
+      break;
+
     default:
       break;
     }
@@ -5369,10 +5380,12 @@ build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1,
 
   /* Add namespace-scope operators to the list of functions to
      consider.  */
-  add_candidates (lookup_function_nonclass (fnname, arglist, /*block_p=*/true),
-		  NULL_TREE, arglist, NULL_TREE,
-		  NULL_TREE, false, NULL_TREE, NULL_TREE,
-		  flags, &candidates, complain);
+  if (!memonly)
+    add_candidates (lookup_function_nonclass (fnname, arglist,
+					      /*block_p=*/true),
+		    NULL_TREE, arglist, NULL_TREE,
+		    NULL_TREE, false, NULL_TREE, NULL_TREE,
+		    flags, &candidates, complain);
 
   args[0] = arg1;
   args[1] = arg2;
diff --git a/gcc/testsuite/g++.dg/template/operator14.C b/gcc/testsuite/g++.dg/template/operator14.C
new file mode 100644
index 0000000..6267dbb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/operator14.C
@@ -0,0 +1,7 @@
+// DR 2007
+// We shouldn't instantiate A<void> to lookup operator=, since operator=
+// must be a non-static member function.
+
+template<typename T> struct A { typename T::error e; };
+template<typename T> struct B { };
+B<A<void> > b1, &b2 = (b1 = b1);

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

only message in thread, other threads:[~2014-11-10  4:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-10  4:49 C++ PATCH for core DR 2007 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).