Patchwork [C++,Patch/RFC] PR 29143

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 15, 2013, 3:44 p.m.
Message ID <52864177.8030500@oracle.com>
Download mbox | patch
Permalink /patch/291604/
State New
Headers show

Comments

Paolo Carlini - Nov. 15, 2013, 3:44 p.m.
Hi,

On 11/12/2013 04:51 PM, Jason Merrill wrote:
> Please add a comment citing 13.3.1.1.  OK with that change.
Thanks. The patch is still unapplied, because there are some 
interactions with access control (and bugs we have got about access 
control) which make me a bit nervous. For example for a testcase like 
the below, with the patch applied we end up emitting two errors: for 
C<&A::f> and then also, redundantly, for return T():

class A
{
   static int f();
};

template<int (*T)()>
struct C
{
   virtual int g()
   {
     return T();
   }
};

void u()
{
   new C<&A::f>();
}

obviously, at some point we have to work on various access control 
issues wrt templates and make sure that consistently in such cases we 
warn for the template argument and only for the argument. By 
consistently I mean, for example, also for C<A::f>.

Anyway, for the time being, the problem filed in 29143 is only about 
OVERLOADs, not about FUNCTION_DECLs, which are already fine, thus I'm 
wondering if we could instead apply something like attached (+ a 
comment). What do you think?

Thanks,
Paolo.

//////////////////////
Jason Merrill - Nov. 15, 2013, 9:08 p.m.
On 11/15/2013 10:44 AM, Paolo Carlini wrote:
> Anyway, for the time being, the problem filed in 29143 is only about
> OVERLOADs, not about FUNCTION_DECLs, which are already fine, thus I'm
> wondering if we could instead apply something like attached (+ a
> comment). What do you think?

Makes sense.

Jason

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 204697)
+++ cp/semantics.c	(working copy)
@@ -2183,6 +2183,10 @@  finish_call_expr (tree fn, vec<tree, va_gc> **args
 	}
     }
 
+  if (TREE_CODE (fn) == ADDR_EXPR
+      && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
+    fn = TREE_OPERAND (fn, 0);
+
   if (is_overloaded_fn (fn))
     fn = baselink_for_fns (fn);
 
Index: testsuite/g++.dg/overload/addr2.C
===================================================================
--- testsuite/g++.dg/overload/addr2.C	(revision 0)
+++ testsuite/g++.dg/overload/addr2.C	(working copy)
@@ -0,0 +1,13 @@ 
+// PR c++/29143
+
+void f(int);
+
+void g(int,int);
+void g(int,int,int);
+
+void
+h ()
+{
+  (&f)(1);
+  (&g)(1,2,3);
+}
Index: testsuite/g++.old-deja/g++.other/overload11.C
===================================================================
--- testsuite/g++.old-deja/g++.other/overload11.C	(revision 204697)
+++ testsuite/g++.old-deja/g++.other/overload11.C	(working copy)
@@ -32,7 +32,7 @@  int main (int argc, char **argv)
   void (*vptr) ();
   
   (ovl) (1);                // ok
-  (&ovl) (1);               // { dg-error "" } not suitable for overload resolution
+  (&ovl) (1);               // ok
   (ovl) ();                 // { dg-error "" } no matching candidates
   // { dg-message "candidate" "candidate note" { target *-*-* } 36 }
   (&ovl) ();                // { dg-error "" } not suitable for overload resolution