https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101707

            Bug ID: 101707
           Summary: deduction of template argument fails via base class
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: baber.nwz at gmail dot com
  Target Milestone: ---

The following program fails to compile with GCC 11.2 but compiles with clang
(from version 12 to 3), MSVC (2015, 2017, 2019) and ICC:

template<typename T>
struct S {};

struct A : S<int> {};
struct B : S<float> {};
struct C : A, B, S<double> {};

template<typename T, template <typename> class TPL>
void f(TPL<T>& a)
{
}

void g()
{
    A a;
    B b;
    C c;

    f<int>(a); // OK
    f<float>(b); // OK
    f<double>(c); // ERROR
}

The compiler gives the following output:
source>: In function 'void g()':
<source>:21:14: error: no matching function for call to 'f<double>(C&)'
   21 |     f<double>(c);
      |     ~~~~~~~~~^~~
<source>:9:6: note: candidate: 'template<class T, template<class> class TPL>
void f(TPL<T>&)'
    9 | void f(TPL<T>& a)
      |      ^
<source>:9:6: note:   template argument deduction/substitution failed:
<source>:21:14: note:   'TPL<T>' is an ambiguous base class of 'C'
   21 |     f<double>(c);
      |     ~~~~~~~~~^~~


With the supplied template parameter (double), the base class is definitely not
ambiguous. 

https://godbolt.org/z/EKn16o46a

Reply via email to