[35.20] Can the previous problem hurt me silently? Is it possible that the compiler will silently generate the wrong code?
Yes.
Since non-dependent types and
non-dependent members are not
found in the dependent template base-classes, the compiler will search the
enclosing scope, such as the enclosing namespace. This can cause it to
silently(!) do the wrong thing.
For example:
class Xyz { ... }; ← global ("namespace scope") type
void f() { } ← global ("namespace scope") function
template<typename T>
class B {
public:
class Xyz { ... }; ← type nested in class B<T>
void f() { } ← member of class B<T>
};
template<typename T>
class D : public B<T> {
public:
void g()
{
Xyz x; ← suprise: you get the global Xyz!!
f(); ← suprise: you get the global f!!
}
};
The use of
Xyz and
f within
D<T>::g() will silently(!)
resolve to the global entities rather than those inherited from class
B<T>.
You have been warned.