3

According to this page: http://womble.decadent.org.uk/c++/template-faq.html#non-dependent "Non-dependent names are those names that are considered not to depend upon the template parameters, plus the name of the template itself and names declared within it (members, friends and local variables)"

This appears to be backed up by the fact that the following code is considered valid (by LLVM/Comeau)

template<typename T>
struct Template
{
    typedef int I;
    typedef Template::I Type; // 'Template' is NOT dependent
    typedef Template<T>::I Type2; // 'Template<T>' is NOT dependent
    Template<T>* m;
    void f()
    {
        m->f(); // 'm' is NOT dependent
    }
};

After spending some time reading the C++ 98 standard, I cannot find where this behaviour is specified. I would expect to find a mention of this under 'temp.nondep'.

willj
  • 2,991
  • 12
  • 24
  • Note, since C++11 there's now a bunch of language concerning "A name refers to the *current instantiation* if" that's involved in such usage. – Ben Voigt Jan 13 '15 at 21:41

1 Answers1

1

The C++98 standard does not define what is exactly meant by "non-dependent", "nondependent" or "not dependent" names (you can find all three forms in standard texts).

Instead it chooses to define what names and types are dependent on template arguments in 14.6 [temp.res] and its sub-chapters. Simple logic applied ... everything that is not said to be dependent is non-dependent. Only reading 14.6.3 [temp.nondep] does not help.

Öö Tiib
  • 10,809
  • 25
  • 44
  • 1
    A re-reading of 14.6 [temp.res] answers my question: "Three kinds of names can be used within a template definition: - The name of the template itself, and names declared within the template itself - Names dependent on a template-parameter - Names from scopes which are visible within the template-definition." This implies that the name of the template is excluded from the 'Names dependent on a template parameter' set. – willj Sep 22 '12 at 14:17
  • @willj Yes, you did answer your own question more clearly than me. :) – Öö Tiib Sep 22 '12 at 18:14