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

            Bug ID: 96976
           Summary: g++ reports "call of overloaded '...' is ambiguous"
                    when universal reference is used
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: igor.chorazewicz at intel dot com
  Target Milestone: ---

Following code compiles fine on clang++ and gcc 11 but fails on all older gcc
versions I tested (9.3.0, 9.2.1, 10.0.1).

#include <type_traits>

template <typename... Args>
void f(int &&a, Args&&... args)
{
}

template <typename K, typename... Args, typename = typename
std::enable_if<true, K>::type>
void f(K&& k, Args&&... args)
{
}

int main() {
    f(1, 2);
    return 0;
}

The error is:
prog.cc: In function 'int main()':
prog.cc:14:11: error: call of overloaded 'f(int, int)' is ambiguous
   14 |     f(1, 2);
      |           ^
prog.cc:4:6: note: candidate: 'void f(int&&, Args&& ...) [with Args = {int}]'
    4 | void f(int &&a, Args&&... args)
      |      ^
prog.cc:9:6: note: candidate: 'void f(K&&, Args&& ...) [with K = int; Args =
{int}; <template-parameter-1-3> = int]'
    9 | void f(K&& k, Args&&... args)


Note that if I remove the dummy enable_if, the program compiles fine. It also
compiles if there is no template parameter pack (Args...)

Reply via email to