Description
[temp.explicit]/4:
[...] If the explicit instantiation is for a function or member function, the unqualified-id in the declarator shall be either a template-id or, where all template arguments can be deduced, a template-name or operator-function-id.
[Note 1: The declaration can declare a qualified-id, in which case the unqualified-id of the qualified-id must be a template-id. —end note]
I don't know what this note is trying to say, but it appears to flat-out contract the previous normative sentence that allows the unqualified-id to be a template-name or operator-function-id.
But I think both the note and the normative sentence here are nonsense. Consider the immediately following sentence:
If the explicit instantiation is for a member function, a member class or a static data member of a class template specialization, the name of the class template specialization in the qualified-id for the member name shall be a simple-template-id.
So if the explicit instantiation is for a member function of a class template specialization, then we are required to have Class<args>::Function<more args>
, even if the function is a non-template member function? What?
I think we meant something more like:
[temp.explicit]/4:
If the explicit instantiation is for a class
or member class, the elaborated-type-specifier in the declaration shall include a simple-template-id; otherwise, the declaration shall be a simple-declaration whose init-declarator-list comprises a single init-declarator that does not have an initializer. If the explicit instantiation is for a functionor member functiontemplate specialization, the unqualified-id in the declarator shall be either a template-id or, where all template arguments can be deduced, a template-name or operator-function-id.
[Note 1: The declaration can declare a qualified-id, in which case the unqualified-id of the qualified-id must be a template-id. —end note]
If the explicit instantiation is for a memberfunction, a member class or a static data memberof a class template specialization, the name of the class template specialization in the qualified-id for the member name shall be a simple-template-id. If the explicit instantiation is for a variable template specialization, the unqualified-id in the declarator shall be a simple-template-id. An explicit instantiation shall appear in an enclosing namespace of its template. If the name declared in the explicit instantiation is an unqualified name, the explicit instantiation shall appear in the namespace where its template is declared or, if that namespace is inline (9.8.2), any namespace from its enclosing namespace set.
... but this is still wrong, given that it doesn't properly handle a member of a member of a class template specialization. (The above also loses the restriction that you can't explicitly instantiate an untemplated function.)
Activity
jensmaurer commentedon Nov 17, 2021
Do we want to retain the gist of the note by adding "(possibly appearing in a qualified-id)" after "unqualified-id in the declarator"?
I'm not seeing the updated text to change anything in that regard, if we assume that a "function template specialization" only exists for a function template.
I'm also wondering whether the quoted text has the logic backward: It should derive the entity to be instantiated from the syntax used, but it's establishing syntax restrictions based on divining the programmer's intent ("If the explicit instantiation is for X...": how do we know it's "for X"?)
tkoeppe commentedon Jun 12, 2023
Editorial meeting decision: this is not editorial. There clearly is an issue here, but it's best for Core to take a look.