This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Static data members in template declarations
- To: tim at wagner dot princeton dot edu
- Subject: Re: Static data members in template declarations
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Mon, 2 Nov 1998 22:33:38 -0800
- CC: martin at mira dot isdn dot cs dot tu-berlin dot de, egcs at cygnus dot com
- References: <199811030611.BAA18800@wagner.Princeton.EDU>
- Reply-to: mark at markmitchell dot com
>>>>> "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