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]
Other format: [Raw text]

[Bug c++/51613] New: Ambiguous function template instantiations as template argument are not rejected


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51613

             Bug #: 51613
           Summary: Ambiguous function template instantiations as template
                    argument are not rejected
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: pkmx.tw@gmail.com


In the book "C++ Templates - The Complete Guide" section 8.3, the following
code snippet is given:

template<typename F, typename T>
void apply(F f, T t)
{
    f(t);
}

template<typename T>
void multi(T)
{
}

template<typename T>
void multi(T*)
{
}

int main()
{
    apply(&multi<int>, 7);

    return 0;
}

My understanding is that &multi<int> here instantiates two functions of types
void (*)(int) and void (*)(int*) with no ways to disambiguate and therefore F
cannot be deducted. However, gcc currently deducts F as void (*)(int) and
ultimately calls multi(int). This is the same case for gcc 4.4.3, gcc 4.6.2,
gcc 4.7.0 20111112 snapshot and probably other versions.


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