The following snippet compiles fine in vc++ and clang++, but fails on gcc (inc 9.2) unless i add an explicit cast. Which compiler is right here?
#include <initializer_list>
template<typename T>
void Task(void) {}
int main()
{
for(auto p_task: {&Task<int>}) {} // error
// for(auto p_task: {static_cast<void (*)(void)>(&Task<int>)}) {} // ok
}
<source>: In function 'int main()':
<source>:8:33: error: unable to deduce 'std::initializer_list<auto>&&' from '{(& Task<int>)}'
8 | for(auto p_task: {&Task<int>}) {} // error
| ^
<source>:8:33: note: couldn't deduce template parameter 'auto'
auto l = { &Task<int> };
does the same (live demo). – Lutero+Task<int>
which implies the&Task<int>
might have a type ambiguity in gcc that's not present for implicit conversion. For instance gcc might simply ignore the&
when applied to a global function, which then has an ambiguity ofvoid(*)()
vsvoid()
orvoid(&)()
. Or something... I'd send in a ticket. – Fulminate{ std::addressof(Task<int>) }
which may help you with a possibly more pleasing workaround (though the unary plus is always a crowd pleaser). – Grad