G ++ and clang ++ various behavior that displays the return type of a function template

Another who is right between g ++ and clang ++? question for standard C ++ gurus.

Next program

#include <iostream> void foo (int v) { std::cout << "foo(), int version (" << v << ')' << std::endl; } void foo (double v) { std::cout << "foo(), double version (" << v << ')' << std::endl; } template <typename T, typename R> void bar (T v, R(*fn)(T)) { fn(v); } int main () { bar(1, foo); } 

compile and run with g ++ (6.3.0, but also from 8.0.0 on Wandbox), but compiling it with clang ++ (3.9.1, but also from 6.0.0 on Wandbox), I get the following error

 tmp_002-11,14,gcc,clang.cpp:29:4: error: no matching function for call to 'bar' { bar(1, foo); } ^~~ tmp_002-11,14,gcc,clang.cpp:25:6: note: candidate template ignored: couldn't infer template argument 'R' void bar (T v, R(*fn)(T)) ^ 1 error generated. 

As usual, the question is: who is right? g ++ or clang ++?

+8
c ++ type-inference templates g ++ clang ++
source share

No one has answered this question yet.

See related questions:

33
Calling the `this` member function from a common lambda-clang vs gcc
12
Why clang rejects a variable function template name
nine
Explicit specification of a nested class: behavior of different compilers
8
g ++ and clang ++ different behavior with friend template function defined inside template class
6
g ++ and clang ++ different behavior with variable template and SFINAE
5
specialized function in the namespace
3
Template parameter package does not work on Clang, but not VS 2015
3
C ++ STL type_traits question
2
g ++ and clang ++ different behavior with non-type argument in struct / class specialization
0
Output type return for class template functions in clang

All Articles