Static members in templates in egcs-1.0.1
Erik Corry
erik@arbat.com
Wed Jan 14 04:17:00 GMT 1998
On Tue, Jan 13, 1998 at 09:51:13AM -0800, Joe Buck wrote:
> Erik Corry
> > But it seems that static members of templates still don't work:
>
> Yes they do, if you use the correct syntax.
Ooops! Thanks for the correction.
> I think the reason you aren't getting a message is because of a GNU
> extension (permitting initialization of members within classes) that
> has suffered from bit rot (no one ever tried this case). It would be
> best to just diagnose your code as an error, since it isn't going to work.
It seems it does work, if you also have the file-scope declaration
(without initialisation), so it's going to be difficult to warn about.
According to the comments in in cp/decl.c:
/* Motion 10 at San Diego: If a static const integral data
member is initialized with an integral constant
expression, the initializer may appear either in the
declaration (within the class), or in the definition,
but not both. If it appears in the class, the member is
a member constant. The file-scope definition is always
required. */
so it is allowed (ie not a GNU extension) for const integral
types. One real 'bug' is that:
struct F
{
static int t = 1;
};
int F::t = 0;
will silently override the initialisation in the class declaration
and use the file-scope one, even with -Wall. If you leave the
initialisation off one of the places it works though. The same
applies with templates.
I will now go back to lurking.
--
Erik Corry erik@arbat.com
More information about the Gcc
mailing list