This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[C++BUG] template fn deduction


Hi,
I was looking at PR46 which concerns implicit & on overloaded
member fns (you only need the & if it resolves to a non-static
member). I think the following is well-formed

        struct B
        {
          static int foo (int);
          int foo (float);
        };

        template <typename T> void fn (int (*ptr) (T));    //1
        template <typename T> void fn (int (B::*ptr) (T)); //2

        void foo ()
        {
          fn (B::foo);  // should select 1
        }

pr46a.C: In function `void foo ()':
pr46a.C:12: call of overloaded `fn ({unknown type})' is ambiguous
pr46a.C:7: candidates are: void fn (int (*) (T)) [with T = int]
pr46a.C:8:                 void fn (int (A::*) (T)) [with T = float]

[14.8.2.1] talks about P the template function parameter type and
the corresponding argument of the call A. The two choices in the
above are

        1               2
T       int             float
P       int (*)(int)    int (A::*)(float)
A       int ()(int)     int (A::)(float)
A'      int (*)(int)

A is a function type in both case, so function-to-pointer standard
conversion is applied [4.3]. That conversion never applies to
nonstatic member functions (as an lvalue that refers to one of those
cannot be obtained). So for case 1 A decays to A' via second option.
That doesn't occur for case 2, so type deduction fails. Therefore
the only candidate for overload resolution is 1, and the example is
well formed.

Could someone either confirm my reasoning, or tell me where I'm
wrong.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]