1
以下代碼適用於gcc甚至VC11 Nov CTP,但無法使用VC11 RTM進行編譯。VS2012 - Decltype作爲尾隨返回類型中的模板參數
template<typename T>
struct A {
typedef typename T::Type BreakMe;
T x;
};
struct B { typedef int Type; };
template<typename T>
struct C {
static A<T> f(A<T> a) {
return A<decltype(a.x)>();
}
static auto g(A<T> a) -> A<decltype(a.x)> {
return A<decltype(a.x)>();
}
};
int main(int argc, char* argv[])
{
C<B>::f(A<B>());
C<B>::g(A<B>());
return 0;
}
- VC11 RTM:http://rise4fun.com/Vcpp/9u2
- VC11 CTP:http://rise4fun.com/Vcpp/6lS
VC11 RTM似乎會失敗decltype傳遞作爲一個返回值的模板參數:它認爲「T =未知」。請注意,f
編譯良好,儘管在其中使用了decltype。
這是RTM中的編譯器錯誤嗎?如果是這樣,是否有解決方法?