【发布时间】:2012-02-21 04:05:46
【问题描述】:
这曾经在几周前起作用:
template <typename T, T t>
T tfunc()
{
return t + 10;
}
template <typename T>
constexpr T func(T t)
{
return tfunc<T, t>();
}
int main()
{
std::cout << func(10) << std::endl;
return 0;
}
但现在g++ -std=c++0x 说:
main.cpp: In function ‘constexpr T func(T) [with T = int]’:
main.cpp:29:25: instantiated from here
main.cpp:24:24: error: no matching function for call to ‘tfunc()’
main.cpp:24:24: note: candidate is:
main.cpp:16:14: note: template<class T, T t> T tfunc()
main.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
clang++ -std=c++11 表示模板的tfunc<T, t>() 参数因为无效而被忽略。
这是一个错误,还是一个修复?
PS:
g++ --version => g++ (GCC) 4.6.2 20120120 (prerelease)
clang++ --version => clang version 3.0 (tags/RELEASE_30/final) (3.0.1)
【问题讨论】:
-
FWIW,Clang 3.1 HEAD 也出现同样的错误。
标签: c++ gcc c++11 metaprogramming constexpr