我不確定它是Clang 3.2中的錯誤還是違反了C++ 03,但似乎模板類的模板化構造函數的顯式實例化失敗,但顯式實例化了模板化模板類的成員函數成功。模板類的模板化構造函數的顯式實例化
例如,下面的編譯沒有一個問題都鐺++和g ++:
template<typename T>
class Foo
{
public:
template<typename S>
void Bar(const Foo<S>& foo)
{ }
};
template class Foo<int>;
template class Foo<float>;
template void Foo<int>::Bar(const Foo<int>& foo);
template void Foo<int>::Bar(const Foo<float>& foo);
template void Foo<float>::Bar(const Foo<int>& foo);
template void Foo<float>::Bar(const Foo<float>& foo);
而沒有與G ++警告以下編譯但失敗鐺++:
template<typename T>
class Foo
{
public:
template<typename S>
Foo(const Foo<S>& foo)
{ }
};
template class Foo<int>;
template class Foo<float>;
template Foo<int>::Foo(const Foo<int>& foo);
template Foo<int>::Foo(const Foo<float>& foo);
template Foo<float>::Foo(const Foo<int>& foo);
template Foo<float>::Foo(const Foo<float>& foo);
特別地,我看到兩種形式的錯誤消息:
TemplateMember.cpp:12:20: error: explicit instantiation refers to member
function 'Foo<int>::Foo' that is not an instantiation
template Foo<int>::Foo(const Foo<int>& foo);
^
TemplateMember.cpp:9:16: note: explicit instantiation refers here
template class Foo<int>;
^
這是違規行爲的標準或鏗鏘++錯誤?
看起來像有效的C++ 03。可能在Clang中出現bug ++ – 2013-02-23 21:34:30