Reputation: 40068
Consider the following code:
#include <initializer_list>
struct X{
static void init(const std::initializer_list<void*>& ptrs){}
};
template <typename T>
struct Y{
static void foo(){
X::init({ nullptr });
}
};
The function foo
of class template Y<T>
calls X::init
with an initializer list with a single nullptr
. Should work fine, shouldn't it?
However, my g++ 4.6.1 complains:
test11.cpp: In static member function 'static void Y<T>::foo()':
test11.cpp:12:23: error: no matching function for call to 'X::init(<brace-enclosed initializer list>&)'
test11.cpp:12:23: note: candidate is:
test11.cpp:5:15: note: static void X::init(const std::initializer_list<void*>&)
test11.cpp:5:15: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::initializer_list<void*>&'
Once I remove the template parameter from Y
, i.e. make it a normal class, everything works fine. What am I doing wrong or is this a compiler bug?
Upvotes: 2
Views: 290
Reputation: 117701
This is almost definitely a compiler bug, seeing that it works in later versions of GCC (see comments). I personally don't see a reason why it shouldn't work.
Upvotes: 1