This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Static data members in template declarations


Mark Mitchell writes ...
> 
> Your approach, however, would require that we cart around all
> declarations and definitions that have anything to do with a template
> class until instantiation time, and then merge/complain and otherwise
> analyze them then.  Not only is this burdensome from an implementation
> point of view, it also does not seem, to me, to be what anyone
> intended w.r.t. templates.  For example,
> 
>   template <class T>
>   struct S {
>     int f();
>   };
> 
>   template <class T>
>   T S<T>::f() {}
> 
> You're proposing (at least by logical extension) that this is kosher
> as long as you only instantiate S with `int'.  That seems peculiar.

And the logic for disallowing it is ... ?  The language in the C++ standard
that forbids it is ... ?

The following code is also "peculiar":

template <class T>
struct S {
    int *f() { return new T; }
};

but it certainly is legal C++, despite the fact that anything other than
S<int> is an error.

I fail to see how the error "return to `int *' from `double *'" is
fundamentally different from "new declaration `double S<double>::f()'
ambiguates old definition `int S<double>::f()'".

---------------------------------------------------------------------------
Tim Hollebeek                           | "Everything above is a true
email: tim@wfn-shop.princeton.edu       |  statement, for sufficiently
URL: http://wfn-shop.princeton.edu/~tim |  false values of true."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]