This code does not compile: template <class T> struct Feature { friend void AssertFeature0(T *) {} }; template <class T> inline void AssertFeature(T *t = 0) { if(t) AssertFeature0(t); } template <class T> struct Test : Feature< Test<T> > { int i; ~Test() { AssertFeature<T>(); } }; struct Foo : Feature<Foo> { int x; }; void foo() { Test< Test<Foo> > test; } ---------------------- The problem seems to be in fact that ~Test destructor is instantiated BEFORE friend is injected and only in the case that templates are nested. Moving AssertFeature to other method (and instatiating) or reducing test-case to just "Test<Foo> test;" makes code compile fine. Comeau C++ testdrive compiles this code without problems.
*** This bug has been marked as a duplicate of 22363 ***