Bug 77335 - templates and ambiguous call to overloaded function
Summary: templates and ambiguous call to overloaded function
Status: RESOLVED DUPLICATE of bug 67829
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-08-23 00:22 UTC by brahmin
Modified: 2021-12-09 17:04 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-12-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description brahmin 2016-08-23 00:22:03 UTC
In some cases, function overloading seems to create ambiguity. When the function contains multiple template arguments. Encountered on MSVC2015, and tested at : http://melpon.org/wandbox/permlink/mtfWJXEtQ8lEP8ub

template<class> struct A { };
template<template<class> class, class> struct B { };
template<class, class> struct C { };

template<template<class> class TT, class T, class U> void f(TT<T>, B<TT, T>, U) { }
template<template<class> class TT, class T, class V> void f(TT<T>, B<TT, T>, C<TT<T>, V>) { }

int main()
{
   A<int> a;
   B<A, int> b;
   C<A<int>, long> c;
   f(a, b, c);//ambiguity error
}

--------------------------------------------------
Another example :

template <class T>
class BX {
public :
    BX() {}
    ~BX() {}
};

template <class T1, class T2>
class G {
public :
    G() {}
    ~G() {}
};

template <template <class T> class T1, class T>
class DT {};

class B {
public :
    template <template <class T> class T1, class T, class M>
    static void func(const M& m, const DT<T1, T>* dt, T1<T>& val) {}

    template <template <class T> class T1, class T, class M>
    static void func(const G<T1<T>, M>& g, const DT<T1, T>* dt, T1<T>& val) {}

    //here is a small variation of func as a test
    template <template <class T> class T1, class T, class M>
    static void func2(const M& m, const DT<T1, T>* dt) {}

    template <template <class T> class T1, class T, class M>
    static void func2(const G<T1<T>, M>& g, const DT<T1, T>* dt) {}
};

int main() {
    BX< int > bx;
    G<BX< int >, int> g;
    DT<BX, int>* dt;
    B::func(g, dt, bx);//Error  C2668   'B::func': ambiguous call to overloaded function
    B::func2(g, dt);//no error
}

Problem also submitted at : http://stackoverflow.com/questions/39060180/c-templates-and-ambiguous-call-to-overloaded-function
Comment 1 Andrew Pinski 2021-08-09 21:28:39 UTC
This seems fixed on the trunk.
Comment 2 Martin Liška 2021-12-09 08:58:02 UTC
Fixed with r12-1374-gedec2660ff4890ec.
Comment 3 Andrew Pinski 2021-12-09 17:04:44 UTC
Dup of bug 67829

*** This bug has been marked as a duplicate of bug 67829 ***