Hi,

in this very old issue we reject:

void f(int,int);
void f(int,int,int);

void g ()
{
    (&f)(1,2,3);
}

with "address of overloaded function with no contextual type information".

It seems to me that handling the ADDR_EXPR close to the beginning of finish_call_expr goes a long way toward fixing the problem. As regards the existing testsuite, besided the obvious g++.old-deja/g++.other/overload11.C tweak, there is the sightly more interesting case of g++.dg/template/call4.C: withe the patch applied, we start rejecting it, because we notice that propGetDouble is private. AFAICS, that's progress, but in principle we should detect the access violation even earlier, when we pass the address of propGetDouble as template argument: the bug is already in Bugzilla (c++/48078, maybe there are dups too). Thus I think this testsuite tweak is also fine.

Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////


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
+      && is_overloaded_fn (TREE_OPERAND (fn, 0)))
+    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++.dg/template/call4.C
===================================================================
--- testsuite/g++.dg/template/call4.C   (revision 204697)
+++ testsuite/g++.dg/template/call4.C   (working copy)
@@ -2,7 +2,7 @@
 
 class OFX_PropertySuiteV1
 {
-  static int propGetDouble ();
+  static int propGetDouble ();       // { dg-error "private" }
 };
 template<int dimension,
         class T,
@@ -12,7 +12,7 @@ struct OFX_AnimatedNumberParam
 {
   virtual int paramSetValueAtTime()
   {
-    return PROPGET();
+    return PROPGET();                // { dg-error "context" }
   }
 };
 void  f()
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

Reply via email to