Topic: template example incorrect in dec96 draft?


Author: John Lilley <jlilley@empathy.com>
Date: 1997/01/20
Raw View
Hi,

I've recently sent a comment to the C++ standards feedback mail address,
to the effect that the example given in 14.6.2/2 is incorrect, given the
new language in the dec96 draft:

   template<class T> class Z {
   public:
      void f() { g(1); }
   };
   void g(int);
   void h (Z<Horse>& x) { x.f(); }   // ill-formed call to x.f()

Actually, I have no problem with *this* example, it's the one that
follows in 14.6.2/3:

   void h(Z<int>& y) { y.f(); }      // OK, g(1) depends on parameter

It is claimed that the call g(1) is dependent on the template type
argument only when the type argument is "int".  However, this is not
supported by the definition of dependency.  14.6.2/1 claims that a
postfix expression such as g(1) is dependent on a type parameter "if and
only if any of the expressions in the epression-list is a type-dependent
expression", which I take to mean that the literal "1" must be
type-dependent for g(1) to be type-dependent.  The unintuitiveness of
this idea aside, 14.6.2.2/5 explicitly says that a literal is never
type-dependent, so that example is incorrect.

The problem is that the examples given demonstrate a dependency on a
template *argument*, whereas the dependency rules define dependency in
terms of template *parameters*.  Dependency on a template argument
implies that any declaration or expression involving use of a type that
*happens to be the same* as a type used as a template argument is fair
game for being rendered "dependent" (or not) at the time of template
instantiation.  This in turn implies that all declarations may be
rebound during the instantiation, given the right context.

I think that the new language clearly states that names are dependent if
and only if they are dependent on a formal template parameter, and this
in turn can be determined statically when the template declaration is
processed.  This is further supported by 14.6.2/5, which disallows
members of a template-argument used as a base class from hiding names
that were bound during processing of the template declaration.

Is this analysis of the dec96 draft correct, or at least plausible?

john lilley
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]