Title
Syntax of explicit instantiation/specialization too permissive
Status
open
Section
13.9.3 [temp.explicit]
Submitter
Mark Mitchell

Created on 2001-06-27.00:00:00 last changed 34 months ago

Messages

Date: 2022-02-18.07:47:23

Suggested resolution:

I think we should say:

    explicit-instantiation:
      type-specifier-seqopt declaratoropt ;

[Steve Adamczyk: presumably, this should have template at the beginning.]

and then say that:

  • The declarator can be omitted only when the type-specifier-seq consists solely of an elaborated-type-specifier for a class type, in which case the instantiation is for the named class. If the declarator is present the instantiation is for the named entity.
  • The type-specifier-seq can be omitted only when the declarator is for a constructor, destructor, or conversion operator.
  • The type-specifier-seq cannot define any new types.

There are similar problems in 13.9.4 [temp.expl.spec]:

    explicit-specialization:
      template <> declaration

Here, I think we want:

    explicit-specialization:
      decl-specifier-seqopt init-declaratoropt ;

with similar restrictions as above.

[Steve Adamczyk: This also needs to have template <> at the beginning, possibly repeated.]

Date: 2022-02-18.07:47:23

13.9.3 [temp.explicit] defines an explicit instantiation as

    explicit-instantiation:
      template declaration

Syntactically, that allows things like:

    template int S<int>::i = 5, S<int>::j = 7;

which isn't what anyone actually expects. As far as I can tell, nothing in the standard explicitly forbids this, as written. Syntactically, this also allows:

    template namespace N { void f(); }

although perhaps the surrounding context is enough to suggest that this is invalid.

History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6669
2001-06-27 00:00:00admincreate