Title
Unused local classes of function templates
Status
cd4
Section
13.9.2 [temp.inst]
Submitter
Johannes Schaub

Created on 2012-03-25.00:00:00 last changed 49 months ago

Messages

Date: 2014-11-15.00:00:00

[Moved to DR at the November, 2014 meeting.]

Date: 2013-04-15.00:00:00

Notes from the April, 2013 meeting:

The proposed resolution interacts with N3649 (generic lambdas), adopted at this meeting, and this issue has returned to "review" status to allow any necessary changes to be made.

Date: 2012-10-15.00:00:00

Proposed resolution (October, 2012):

Change 13.9.2 [temp.inst] paragraph 1 as follows:

Unless a class template specialization has been explicitly instantiated (13.9.3 [temp.explicit]) or explicitly specialized (13.9.4 [temp.expl.spec]), the class template specialization is implicitly instantiated when the specialization is referenced in a context that requires a completely-defined object type or when the completeness of the class type affects the semantics of the program. [Note: Within a template declaration, a local class or enumeration and the members of a local class are never considered to be entities that can be separately instantiated (this includes their default arguments, exception-specifications, and non-static data member initializers, if any). As a result, the dependent names are looked up, the semantic constraints are checked, and any templates used are instantiated as part of the instantiation of the entity within which the local class or enumeration is declared. —end note] The implicit instantiation of a class template specialization...
Date: 2012-03-25.00:00:00

Do local classes of function templates get the same treatment as member classes of class templates? In particular, is their definition only instantiated when they are required? For example,

  template<typename T> void f() {
    struct B {
      T t;
    };
  }

  int main() {
    f<void>();
  }

Implementations vary on this question.

(This question is superficially similar to the one in issue 1253. However, the entities in view in that issue can be named and defined outside the containing template and thus can be explicitly specialized, none of which is true for local classes of function templates.)

It should also be noted that the resolution of this issue should apply as well to local enumeration types.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5416
2014-11-24 00:00:00adminsetstatus: ready -> dr
2014-03-03 00:00:00adminsetstatus: review -> ready
2013-05-03 00:00:00adminsetmessages: + msg4322
2013-05-03 00:00:00adminsetstatus: tentatively ready -> review
2012-11-03 00:00:00adminsetmessages: + msg4080
2012-11-03 00:00:00adminsetstatus: open -> tentatively ready
2012-03-25 00:00:00admincreate