Why does member function of class template get constructed in this case?

1
2
3
4
5
6
7
8
9
10
struct ABC {};

template<typename T>
class DEF
{
   void f0(typename T::ab) {} //ERROR
   void f1() {typename T::ab var;} //Fine
};

DEF<ABC> obj;


I thought if I don't use a particular member function of a class template it never gets constructed by the compiler. Hence as expected even with f1() compiles fine because obj never uses it. Why does f0() result in compile error? I'm not using that too.
To quote 14.7.2[temp.inst]

The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or the class member functions,


So the instantiation at line 10 requires that the declarations of both f0 and f1 are valid, and the non-existent type T::ab is part of the declaration of f0.
thank you.

The implicit instantiation of a class template specialization
Is this meant to deal with class template specialization? Because I haven't specialized DEF. (That's one of the reasons I generally can't fully comprehend the draft/standard - I get confused by the wordings and lack of thorough knowledge of the language)
"specialization" is whenever generic T becomes specific, in this case, ABC, which may be implicit (done by the compiler) or explicit (done by you). That paragraph deals with both.

When you specialize DEF for something, you're providing explicit specialization
Last edited on
clear now. :)
Topic archived. No new replies allowed.