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++/69056] New: GCC failed with variadic template and pointer to member function


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

            Bug ID: 69056
           Summary: GCC failed with variadic template and pointer to
                    member function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastien at chapuis dot co
  Target Milestone: ---

$cat test.cpp
#include <memory>
#include <iostream>

class           Manager
{
public:
  Manager() {}
  virtual ~Manager() {}

  int funcA(std::shared_ptr<int> a, float b) { return *a + b; }
  int funcA(std::shared_ptr<double> a) { return *a; }
};

template <typename T, typename... Args>
auto resolver(int (Manager::*func)(std::shared_ptr<T>, Args...)) ->
decltype(func) {
  return func;
}                                                                               

int main(int, char **)
{
  Manager m;
  Manager *ptr = &m;

  auto var = std::make_shared<int>(1);

  int result = (ptr->*resolver<int>(&Manager::funcA))(var, 2.0);

  std::cout << result << std::endl;

  return 0;
}
$g++ -std=c++11 test.cpp 
test.cpp: In function 'int main(int, char**)':
test.cpp:29:52: error: no matching function for call to 'resolver(<unresolved
overloaded function type>)'
   int result = (ptr->*resolver<int>(&Manager::funcA))(var, 2.0);
                                                    ^
test.cpp:15:6: note: candidate: template<class T, class ... Args> decltype
(func) resolver(int (Manager::*)(std::shared_ptr<_Tp1>, Args ...))
 auto resolver(int (Manager::*func)(std::shared_ptr<T>, Args...)) ->
decltype(func) {
      ^
test.cpp:15:6: note:   template argument deduction/substitution failed:
test.cpp:29:52: note:   mismatched types 'std::shared_ptr<int>' and
'std::shared_ptr<double>'
   int result = (ptr->*resolver<int>(&Manager::funcA))(var, 2.0);
                                                    ^
test.cpp:29:52: note:   could not resolve address from overloaded function '&
Manager::funcA'
$



This code fails to compile with gcc but is fine with clang or MSVC.
I tried with gcc 5.3.1 and 6.0.0 20151220

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