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++/66670] New: "template argument deduction/substitution failed" with function pointers and multiple parameter packs


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

            Bug ID: 66670
           Summary: "template argument deduction/substitution failed" with
                    function pointers and multiple parameter packs
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michael at ensslin dot cc
  Target Milestone: ---

Take this example:

$ cat t28.cpp
template<class ... Ts>
struct S {
        template<class ... Us>
        void foo(void (*)(Us..., Ts ...)) {}
};

void f(float, int) {}

int main() {
        S<int>().foo<float>(f);
}

$ g++-4.9 -std=c++14 t28.cpp
t28.cpp: In function âint main()â:
t28.cpp:10:23: error: no matching function for call to âS<int>::foo(void
(&)(float, int))â
  S<int>().foo<float>(f);
                       ^
t28.cpp:10:23: note: candidate is:
t28.cpp:4:7: note: template<class ... Us> void S<Ts>::foo(void (*)(Us ..., Ts
...)) [with Us = {Us ...}; Ts = {int}]
  void foo(void (*)(Us..., Ts ...)) {}
       ^
t28.cpp:4:7: note:   template argument deduction/substitution failed:
t28.cpp:10:23: note:   mismatched types âintâ and âfloatâ
  S<int>().foo<float>(f);
                       ^
$ g++-4.9 --version
g++-4.9 (Debian 4.9.2-22) 4.9.2

I have reproduced the issue with g++-5.1.0 using https://gcc.godbolt.org/.

Note that clang++ has this issue as well, but it works with icc and supposedly
even MSVC.

The issue can be fixed by swapping the order of Us... and Ts... in the function
pointer type, or by replacing the function pointer type by some other type like
std::tuple.

Related: http://stackoverflow.com/questions/31040075

clang++ error, for completeness:

$ clang++-3.7 -std=c++14 t28.cpp
t28.cpp:10:11: error: no matching member function for call to 'foo'
        S<int>().foo<float>(f);
        ~~~~~~~~~^~~~~~~~~~
t28.cpp:4:7: note: candidate template ignored: failed template argument
deduction
        void foo(void (*)(Us..., Ts ...)) {}
             ^
1 error generated.

$ clang++-3.7 --version
Debian clang version 3.7.0-svn239806-1+b1 (trunk) (based on LLVM 3.7.0)
Target: x86_64-pc-linux-gnu
Thread model: posix

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