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


>>>>> "Tim" == Tim Hollebeek <tim@wagner.princeton.edu> writes:

    >> template <class T> struct S { int f(); };
    >> 
    >> template <class T> T S<T>::f() {}

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

The standard quite clearly says that the two functions must have the
same type.  Obviously, the issue is *when* this constraint is checked,
and the standard just doesn't say.  So, we get to decide, until
the standard gets updated.  But, I don't see how allowing this case is
doing the programmer any favors, so why should we do what, frankly,
will be a lot of work to do this?  There are no other compilers that
accept this code

    Tim> The following code is also "peculiar":

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

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

Yes, it is legal.  But, it's in an entirely different class, as I'm
sure you'll realize if you think about it carefully.  It's quite a
different thing to ask the compiler to keep around a slew of
declarations and figure out whether they make any sense or not when
things are instantiated vis a vis checking to see (in your case)
whether the function *body* is legal at instantiation time.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com


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