home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!concert!sas!mozart.unx.sas.com!sasghm
- From: sasghm@theseus.unx.sas.com (Gary Merrill)
- Subject: A template or not a template?
- Originator: sasghm@theseus.unx.sas.com
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <Bx9DuJ.3pp@unx.sas.com>
- Date: Thu, 5 Nov 1992 19:51:55 GMT
- Nntp-Posting-Host: theseus.unx.sas.com
- Organization: SAS Institute Inc.
- Keywords: templates
- Lines: 62
-
-
- Well, I've unearthed a copy of the second edition of Lippman
- and find it to be quite good in general (I'll omit any minor
- criticisms I may have at this point). I've been looking at it
- pretty closely (in conjunction with other stuff) and trying to
- extract a semantics for templates. In the process, the following
- (admittedly perverse) example occurred to me:
-
- template <class T> class Foo {
- // Doesn't much matter what's here
- T x;
- };
-
- template <class T> class Foo<int> {
- // Likewise
- T *p;
- };
-
- Now clearly the first is a template-declaration. So is the
- second! Note that since 'Foo' is a template-name, then
- 'Foo<int>' is a template-class-id (I'm using stardard and ARM
- terminology here). Indeed,
-
- class Foo<int> {
- // Likewise
- T *p;
- };
-
- would appear to be a *specialized instance* (Lippman terminology).
- Certainly it has to be counted as a *declaration* if
-
-
- class Foo {
- // Doesn't much matter what's here
- T x;
- };
-
- is a declaration (which it is). In short, the second apparent
- template-declaration follows the grammar and violates no constraints
- I have seen anywhere.
-
- But what does it *mean*? Moreover, what does the use of the new
- template-name ('Foo<int>') mean in various contexts? Consider,
-
- Foo<char> c; // unproblematic
-
- Foo<int><double> d; // Likewise unproblematic, I think.
-
- Foo<int> i; // ?????
-
- Apparently I am not alone in my confusion. The latest version of
- g++ accepts both template-declarations. It handles nicely the
- declaration of 'c' above. On both of the other two declarations
- it suicides with an "Internal compiler error".
-
- Do we perhaps need to tighten up the syntax of template declarations
- a bit? Any thoughts?
-
- --
- Gary H. Merrill [Principal Systems Developer, C Compiler Development]
- SAS Institute Inc. / SAS Campus Dr. / Cary, NC 27513 / (919) 677-8000
- sasghm@theseus.unx.sas.com ... !mcnc!sas!sasghm
-