The following:
template< typename >
struct S;
template< typename T >
S< T >& f (S< T >& s) {
const typename S< T >::nested ignore;
return s;
}
template S< char >& f (S< char >&);
template< typename >
struct S {
struct nested { };
};
compiles with gcc, but not with clang:
$ clang -c /tmp/t.cpp
/tmp/t.cpp:6:20: error: implicit instantiation of undefined template 'S<char>'
const typename S< T >::nested ignore;
^
/tmp/t.cpp:10:21: note: in instantiation of function template specialization 'f<char>' requested here
template S< char >& f (S< char >&);
^
/tmp/t.cpp:2:8: note: template is declared here
struct S;
^
1 error generated.
I believe clang to be right in that, at the point of instantiation, the function f refers an incomplete definition of S. OTOH, a later specialization of S might provide the correct definition that makes the dependent 'nested' well-formed. Any opinions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…