A question regarding template disambiguator was given here:
and in the answer we can read:
ISO C++03 14.2/4
When the name of a member template specialization appears after . or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.
Now here comes my conrete example that I don’t quite understand:
template <class T>
class Base {
public:
template <int v>
static int baseGet() {return v;}
class InnerA {
public:
template <int v>
static int aget() {return v;}
};
class InnerB {
public:
typedef Base BaseType;
typedef BaseType::InnerA OtherType;
template <int v>
static int baseGet() {return BaseType::baseGet<v>();} //(A)
template <int v>
static int aget() {return OtherType::aget<v>();} //(B)
};
};
It obviously fails to compile. You need template in the line (B): OtherType::template aget<v>();.
However, both g++ (4.4.3) and clang++ (2.9) don’t complain about the lack of template in the line (A). Why? BaseType depends on the type T, does it not? Is it a small depart from the standard by those compilers, or do I misunderstand something in the standard?
They implement the C++0x specification, where
Baseis the current instantiation. And C++0x allows to omittemplatekeyword in such a case. SinceBaseTypeis a typedef forBase, when you sayBaseType, that names the current instantiation too.To quote the spec, since you seem to be interested in spec refs
and
and (the modified 14.2/4 that you quoted)
Note: In C++03 your code is ill-formed because both
BaseTypeandOtherTypeare dependent. The spec says:(note that
Baseis equivalent toBase<T>, which is the base on whichBaseandBaseType::InnerAare dependent types).Note that “explicitly depends” in your quote is a pre-standard term, and was gotten rid of fairly lately (I believe it was at December1996). It basically meant (in this context) a qualified-id in which the qualifier is dependent or a class member access (
a->x/a.x) where theawas dependent. After “explicitly depends” was removed from the draft, it was still lurking around at some places, and even C++0x has still references to “explicitly depends” in a note at 14.6.2p2: