Topic: local type not allowed as template-arg -- why??


Author: khan@xraylith.wisc.edu (Mumit Khan)
Date: 1995/10/06
Raw View
In a recent thread in c.l.c++, James Kanze and Fabrice Clerc just
pointed out to me section 14.8.4 of the DWP which says the following:

=====

  14.8  Template arguments                                    [temp.arg]

4 Nor is a local type or a type with no linkage name an acceptable  tem-
  plate-argument.  [Example:
          void f()
          {
              struct S { /* ... */ };
              X<S,p> x3; // error: local type used as template-argument
          }
   --end example]

=====

Why is this necessary? Why isn't the template argument S in X<S,p>
simply treated as X<f()::S, p> (or something along these lines)?

regards,
mumit -- khan@xraylith.wisc.edu
http://www.xraylith.wisc.edu/~khan/
---
[ 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. ]





Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1995/10/06
Raw View
>>>>> "MK" == Mumit Khan <khan@xraylith.wisc.edu> writes:
MK> In a recent thread in c.l.c++, James Kanze and Fabrice Clerc just
MK> pointed out to me section 14.8.4 of the DWP which says the following:
MK> =====
MK>   14.8  Template arguments                                    [temp.arg]

MK> 4 Nor is a local type or a type with no linkage name an acceptable  tem-
MK>   plate-argument.  [Example:
MK>           void f()
MK>           {
MK>               struct S { /* ... */ };
MK>               X<S,p> x3; // error: local type used as template-argument
MK>           }
MK>    --end example]
MK> =====
MK> Why is this necessary? Why isn't the template argument S in X<S,p>
MK> simply treated as X<f()::S, p> (or something along these lines)?

I think this is because the point of instantiation is immediately
_before_ the ``enclosing scope for the point of first use'' (see
[temp.point] 14.3.2/1 for exact wording; also /6 and the rest of
that section).

 Daveed
---
[ 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. ]