Clang 3.2의 버그 또는 C++ 03의 위반인지 확실하지 않지만 템플릿 클래스의 템플릿 생성자에 대한 명시 적 인스턴스화는 실패하지만 템플릿 기반 인스턴스의 명시적인 인스턴스화는 실패합니다 템플릿 클래스의 멤버 함수가 성공합니다. 예를 들어템플릿 클래스에 대한 템플릿 생성자의 명시 적 인스턴스화
에 문제없이 다음 컴파일 모두 그 소리 ++와 g ++ : ++ 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);
그러나 ++ 그 소리와 함께 실패합니다 특히
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);
, I 다음과 같은 두 가지 오류 메시지가 표시됩니다.
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>;
^
위반 사항 clang의 표준 또는 버그의 버그?
유효한 C++ 03처럼 보입니다. 아마 Clang의 버그 ++ –