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 ++?
c ++ type-inference templates g ++ clang ++
max66
source share