cplusplus / cplusplus/draft

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

Open
#5,110 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cwg not-editorial
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

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 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.)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with [temp.explicit]/4 and the quoted normative text and note, then compare the rules for explicit instantiation of functions, member functions, and members of class template specializations. Done means resolving the contradiction and producing wording that also handles members of members without permitting explicit instantiation of an untemplated function.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.