コンパイラのエラーメッセージがもっと役に立ったらすぐに修正できたはずのコンパイラエラーのデバッグに数時間を費やしました。
私はそれを簡単な例に減らしました:
template <typename T>
int f(int);
template <typename U>
auto g(U x) -> decltype(f(x));
int main()
{
g(0);
}
エラーは次のとおりです。
test.cpp: In function 'int main()':
test.cpp:9:8: error: no matching function for call to 'g(int)'
test.cpp:9:8: note: candidate is:
test.cpp:5:29: note: template<class U> decltype (f(x)) g(U)
このエラーは、よくても誤解を招くものではなく、最悪の場合、完全に間違っているのでしょうか。私の見方では、問題は、与えられたgの定義が呼び出しに一致しないということではなく、定義が不正であるということです(decltypeの式f(x)では、指定せずにfを呼び出そうとするため) fのテンプレートパラメータ)。
はるかに合理的なエラーメッセージは次のようなものではないでしょうか。
no matching function for call to 'f(int)' in 'decltype(f(x))'
in instantiation of 'g(U)' with U = int
またはさらに良い:
failed to deduce template parameter 1 in call to 'f(int)' in 'decltype(f(x))'
in instantiation of 'g(U)' with U = int
私はそのような何かを期待していたでしょう...