Topic: File static template functions - illegal?


Author: rani_sharoni@hotmail.com ("Rani Sharoni")
Date: Tue, 17 Dec 2002 18:11:57 +0000 (UTC)
Raw View
"Anthony Williams" <anthony.williamsNOSPAM@anthonyw.cjb.net> wrote in
message news:ptsg509b.fsf@anthonyw.cjb.net...
> rgetov@ultraheap.com (Radoslav Getov) writes:
>
> > Hi folks,
> >
> > For code like this:
> >
> >    template <class T> static void whatever (T);
> >
> > at least one compiler complains with message like:
> >
> >    Warning (Anachronism): "static" is not allowed and is being ignored.
> >
> > Now I know that class templates have external linkage, but is this the
case
> > for template functions, too?
>
> Yes, all templates must have external linkage. Use the anonymous namespace
> instead.
>
That's inaccurate. 3.5/4/6: [...] function template that has internal
linkage.

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#69
Proposed resolution (10/00):

Change the text in 14  temp paragraph 4 from:
A template name may have linkage (3.5  basic.link).
to:
A template name has linkage (3.5  basic.link). A non-member function
template can have internal linkage; any other template name shall have
external linkage. Entities generated from a template with internal linkage
are distinct from all entities generated in other translation units.

Rani


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: abarbati@iaanus.com (Alberto Barbati)
Date: Thu, 5 Dec 2002 22:12:37 +0000 (UTC)
Raw View
Radoslav Getov wrote:
> Now I know that class templates have external linkage, but is this the case
> for template functions, too?

You can have both class and function templates with internal linkage by
just putting them in an anonymous namespace. In fact the use of the
keyword static to mean "internal linkage" has been deprecated (Annex 0,
1.2).

Alberto Barbati



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: anthony.williamsNOSPAM@anthonyw.cjb.net (Anthony Williams)
Date: Fri, 6 Dec 2002 19:42:07 +0000 (UTC)
Raw View
rgetov@ultraheap.com (Radoslav Getov) writes:

> Hi folks,
>
> For code like this:
>
>    template <class T> static void whatever (T);
>
> at least one compiler complains with message like:
>
>    Warning (Anachronism): "static" is not allowed and is being ignored.
>
> Now I know that class templates have external linkage, but is this the case
> for template functions, too?

Yes, all templates must have external linkage. Use the anonymous namespace
instead.

Anthony
--
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rgetov@ultraheap.com (Radoslav Getov)
Date: Wed, 4 Dec 2002 20:07:22 +0000 (UTC)
Raw View
Hi folks,

For code like this:

   template <class T> static void whatever (T);

at least one compiler complains with message like:

   Warning (Anachronism): "static" is not allowed and is being ignored.

Now I know that class templates have external linkage, but is this the case
for template functions, too?

Radoslav Getov

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@attAbi.com ("Victor Bazarov")
Date: Wed, 4 Dec 2002 20:41:19 +0000 (UTC)
Raw View
"Radoslav Getov" <rgetov@ultraheap.com> wrote...
> For code like this:
>
>    template <class T> static void whatever (T);
>
> at least one compiler complains with message like:
>
>    Warning (Anachronism): "static" is not allowed and is being ignored.
>
> Now I know that class templates have external linkage, but is this the
case
> for template functions, too?

I can't find anything related to that in the Standard except that
for the purpose of name lookup only names with external linkage
are considered (14.6.4.2), and only if the name is unqualified.
But there is nothing about 'static' being _not__allowed_...  Or
maybe I am not looking in the right place.

Could it be that the compiler creators got a bit too eager and
dropped 'static' for all global symbols, not just for function
templates?  Does it work if your function 'whatever' is not a
template?

Victor
--
Please remove capital A's from my address when replying by mail


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]