Movatterモバイル変換


[0]ホーム

URL:


Issue 69 - WG21 CWG Issues
Title
Storage class specifiers on template declarations
Status
tc1
Section
9.2.2 [dcl.stc]
Submitter
Mike Ball

Created on1998-10-17.00:00:00 last changed275 months ago

Messages

msg444 (view)
Date: 2000-10-15.00:00:00

Proposed resolution (10/00):

Change the text in Clause 13 [temp] paragraph 4 from:
A template name may have linkage (6.6 [basic.link]).
to:
A template name has linkage (6.6 [basic.link]).A non-member function templatecan have internal linkage; any other template name shall have externallinkage. Entities generated from a template with internal linkage are distinctfrom all entities generated in other translation units.
msg13 (view)
Date: 2022-11-20.07:54:16

Mike Ball: I cannot find anything in the standard that tells me the meaning ofastorage-class-specifier on a function template declaration. Inparticular, there is no indication what effect, if any, it has on the storageclass of the instantiations.

There is an explicit prohibition ofstorage-class-specifierson explicit specializations.

For example, if we have

    template<class T> static int foo(T) { return sizeof(T); }
does this generate static functions for all instantiations? By9.2.2 [dcl.stc]the storage class applies to the name declared in the declarator, whichis the templatefoo, not an instantiation offoo, whichis named with atemplate-id. There is a statement in clause14 that template names have linkage, which supports the contention that"static" applies to the template, not to instantiations.

So what does the specifier mean? Lacking a direct statement inthe standard, I see the following posibilities, in my preference order.

  1. storage-class-specifiers have no meaning on template declarations,their use being subsumed by "export" (for the template name) andthe unnamed namespace (for instantiations)
  2. storage-class-specifiers have no effect on the template name, butdo affect the linkage of the instantiations, though this now applies linkagetotemplate-ids, which I can find no support for. I suspectthis is what was intended, though I don't remember
Of course, if anybody can find some concrete statement, that would settleit.

From John Spicer

The standard does say that a namespace scope template has external linkageunless it is a function template declared "static". It doesn't explicitlysay that the linkage of the template is also the linkage of the instantiations,but I believe that is the intent. For example, a storage class isprohibited on an explicit specialization to ensure that a specializationcannot be given a different storage class than the template on which itis based.

Mike: This makes sense, but I couldn't find much supportin the document. Sounds like yet another interpretation to add tothe list.

John: Agreed.

The standard does not talk about the linkage of instantiations, becauseonly "names" are considered to have linkage, and instances are not reallynames. So, from an implementation point of view, instances have linkage,but from a language point of view, only the template from which the instancesare generated has linkage.
Mike: Which is why I think it would be cleaner to eliminatestorage class specifiers entirely and rely on the unnamed namespace.There is a statement that specializations go into the namespace of thetemplate. No big deal, it's not something it says, so we live withwhat's there.

John: That would mean prohibiting static function templates.I doubt those are common, but I don't really see much motivation for gettingrid of them at this point.

"export" is an additional attribute that is separate from linkage, butthat can only be applied to templates with external linkage.
Mike: I can't find that restriction in the standard,though there is one that templates in an unnamed namespace can't be exported.I'm pretty sure that we intended it, though.

John: I can't find it either. The "inline" case seems tobe addressed, but not static. Surely this is an error as, by definition,a static template can't be used from elsewhere.

Proposed resolution (10/00):

Change the text in Clause 13 [temp] paragraph 4 from:
A template name may have linkage (6.7 [basic.link]).
to:
A template name has linkage (6.7 [basic.link]).A non-member function templatecan have internal linkage; any other template name shall have externallinkage. Entities generated from a template with internal linkage are distinctfrom all entities generated in other translation units.
History
DateUserActionArgs
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2000-11-18 00:00:00adminsetmessages: +msg444
2000-11-18 00:00:00adminsetstatus: ready -> dr
2000-05-21 00:00:00adminsetstatus: drafting -> ready
1999-09-14 00:00:00adminsetstatus: open -> drafting
1998-10-17 00:00:00admincreate

[8]ページ先頭

©2009-2025 Movatter.jp