Bug 61507 - GCC does not compile function with parameter pack.
Summary: GCC does not compile function with parameter pack.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 4.9.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-06-14 01:38 UTC by Cong Hou
Modified: 2014-06-26 10:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-06-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cong Hou 2014-06-14 01:38:12 UTC
GCC fails to compile the following code:



struct A {
  void foo(const int &);
  void foo(float);
};

template <typename... Args>
void bar(void (A::*memfun)(Args...), Args... args);

void go(const int& i) {
  bar<const int &>(&A::foo, i);
}




The error message is shown below:



t.C:10:30: error: no matching function for call to ‘bar(<unresolved overloaded function type>, const int&)’
   bar<const int &>(&A::foo, i);
                              ^
t.C:7:6: note: candidate: template<class ... Args> void bar(void (A::*)(Args ...), Args ...)
 void bar(void (A::*memfun)(Args...), Args... args);
      ^
t.C:7:6: note:   template argument deduction/substitution failed:
t.C:10:30: note:   inconsistent parameter pack deduction with ‘const int&’ and ‘int’
   bar<const int &>(&A::foo, i);



As the type is explicitly specified, why GCC would like to "deduce" it?
Comment 1 Jonathan Wakely 2014-06-14 11:59:29 UTC
(In reply to Cong Hou from comment #0)
> As the type is explicitly specified, why GCC would like to "deduce" it?

Probably because with a variadic template there could be additional arguments that haven't been explicitly specified and so need to be deduced.  However, in this case the number of function arguments should tell the compiler the pack only contains one type, and therefore nothing more needs to be deduced.
Comment 2 Jason Merrill 2014-06-18 22:14:14 UTC
Author: jason
Date: Wed Jun 18 22:13:40 2014
New Revision: 211808

URL: https://gcc.gnu.org/viewcvs?rev=211808&root=gcc&view=rev
Log:
	PR c++/61507
	* pt.c (resolve_overloaded_unification): Preserve
	ARGUMENT_PACK_EXPLICIT_ARGS.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic159.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 3 Jason Merrill 2014-06-19 09:35:20 UTC
Author: jason
Date: Thu Jun 19 09:34:48 2014
New Revision: 211819

URL: https://gcc.gnu.org/viewcvs?rev=211819&root=gcc&view=rev
Log:
	PR c++/61507
	* pt.c (resolve_overloaded_unification): Preserve
	ARGUMENT_PACK_EXPLICIT_ARGS.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/g++.dg/cpp0x/variadic159.C
Modified:
    branches/gcc-4_9-branch/gcc/cp/ChangeLog
    branches/gcc-4_9-branch/gcc/cp/pt.c
Comment 4 Paolo Carlini 2014-06-26 10:17:22 UTC
Thus I would say fixed for 4.9.1.