Skip to content

[temp.explicit] Note disallows explicit instantiation of non-template member functions of a class template specialization #5110

Open
@zygoloid

Description

@zygoloid

[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 function or member function template 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 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. 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

jensmaurer commented on Nov 17, 2021

@jensmaurer
Member

Do we want to retain the gist of the note by adding "(possibly appearing in a qualified-id)" after "unqualified-id in the declarator"?

(The above also loses the restriction that you can't explicitly instantiate an untemplated function.)

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"?)

added
decision-requiredA decision of the editorial group (or the Project Editor) is required.
on Nov 17, 2021
added
cwgIssue must be reviewed by CWG.
and removed
decision-requiredA decision of the editorial group (or the Project Editor) is required.
on Jun 12, 2023
tkoeppe

tkoeppe commented on Jun 12, 2023

@tkoeppe
Contributor

Editorial meeting decision: this is not editorial. There clearly is an issue here, but it's best for Core to take a look.

added
not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.
on Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cwgIssue must be reviewed by CWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zygoloid@tkoeppe@jensmaurer

        Issue actions

          [temp.explicit] Note disallows explicit instantiation of non-template member functions of a class template specialization · Issue #5110 · cplusplus/draft