[Bug c++/88907] New: Variadic template function deduction failure.

Peter.Georg at physik dot uni-regensburg.de gcc-bugzilla@gcc.gnu.org
Fri Jan 18 12:34:00 GMT 2019


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

            Bug ID: 88907
           Summary: Variadic template function deduction failure.
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Peter.Georg at physik dot uni-regensburg.de
  Target Milestone: ---

Created attachment 45462
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45462&action=edit
Code to reproduce bug including possible work-arounds

GCC fails to compile the following code due to alleged ambiguous function call.

```
#include <utility>
template<class T, int... Ns>
class Base
{
};

template<class... Ts, int... Ns>
void error(Base<Ts, Ns...> const &... args)
{
}

template<class... Ts,
    class = std::enable_if_t<
        std::conjunction<std::is_class<std::remove_reference_t<Ts>>...>{}>>
void error(Ts &&... args)
{
}

int main()
{
    Base<int, 4, 4> const a;
    error(a);
}
```

The code is also attached or see: https://godbolt.org/z/GuW-YC

I.e. call to error(Base<int, 4, 4> const &) is ambiguous for GCC.
In my opinion, and e.g. clang agrees with me, the first function is clearly
more specialized and thus should be chosen.

There are two possible work-arounds (both are included in the attached code):
#1: Add an extra function error that takes exactly one parameter of Type
Base<T, Ns...> const &
#2: Remove the default template parameter (SFINAE) from the second error
function

I started I discussion about this (I wasn't sure it is a bug at first) and a
related clang bug (https://bugs.llvm.org/show_bug.cgi?id=40305) here:
https://stackoverflow.com/questions/54236545/why-is-it-an-ambigious-function-call-using-gcc-template-deduction-failing


More information about the Gcc-bugs mailing list