Topic: Template name binding ambiguity
Author: Rick Hollinbeck <rickh@csn.net>
Date: 1995/08/22 Raw View
I've a question about template name binding which I have been unable
to pin down from reading the proposed C++ standard. I've placed this
question twice to comp.std.c++ with no reply. Maybe someone could help,
or point me to someone working on the standard machinery for template
parsing.
I'm trying to update my C++ parser to put it in line with the
standard.
My question is this:
Must type and enum value names from a derived scope based
on a template argument be explicitly qualified with the template argument?
For example,
template<class T>
class A : public T {
typename T::INT i; // binding of INT left until instantiation.
INT i; // Is this illegal, even if T::INT exists?
// how about if a global typedef named INT exists?
void foo() {
enum T::T_ENUM j = T::t_enum_val1; // Must it be written thus?
// or is it...
typename enum T::T_ENUM j = T::t_enum_val1; // Must it be written thus?
// or is it...
typename T::T_ENUM j = T::t_enum_val1; // Must it be written thus?
enum T_ENUM j = t_enum_val1; // Illegal?
T_ENUM j = t_enum_val1; // Illegal?
T::T_ENUM j = T::t_enum_val1; // Illegal?
typename T_ENUM j = t_enum_val1; // Illegal?
}
};
This is very confusing. Seems like template classes based on a template
argument are really a special case and should have a special section in the
standard specifying how name scopes are bound for these template classes.
(Maybe they do, and I missed it.)
I, for one, would like to see a simple rule such as:
Any type or enum value name which should depend on a template argument must
be explicitly qualified by the template argument, both to indicate intent and
to allow the parser to mark it for late binding during instantiation.
This would certainly help both parser writers and code authors to explicitly
request what names they are referencing as they write a class template.
The old macro kludge for templates certainly had its problems, but at
least the programmer could easily visualize what the compiler would do
with their tokens. The current standard's rules are not clear (at the least).
- Rick Hollinbeck
rickh@westernwares.com
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]