Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with gcc but not with clang when compiling initializer list containing pointers to template function

Tags:

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' 

online compiler

like image 805
user7860670 Avatar asked Dec 29 '19 08:12

user7860670


1 Answers

GCC was wrong, but not anymore! Thanks to @Barry reporting it, and Marek Polacek fixing it, the live demo can now be compiled with GCC trunk (future GCC 11).

like image 197
Bulletmagnet Avatar answered Oct 13 '22 13:10

Bulletmagnet