Date
2016-01-15.00:00:00
Message id
5710

Content

Proposed resolution (January, 2016):

  1. Change 13.9.2 [temp.inst] paragraph 1 as follows, moving the note and example from paragraph 6 and breaking it into two paragraphs:

  2. 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: In particular, if the semantics of an expression depend on the member or base class lists of a class template specialization, the class template specialization is implicitly generated. For instance, deleting a pointer to class type depends on whether or not the class declares a destructor, and a conversion between pointers to class type depends on the inheritance relationship between the two classes involved. —end note] [Example:

      template<class T> class B { /* ... */ };
      template<class T> class D : public B<T> { /* ... */ };
    
      void f(void*);
      void f(B<int>*);
    
      void g(D<int>* p, D<char>* pp, D<double>* ppp) {
        f(p);            // instantiation of D<int> required: call f(B<int>*)
        B<char>* q = pp; // instantiation of D<char> required:
                         // convert D<char>* to B<char>*
        delete ppp;      // instantiation of D<double> required
    }
    

    end example] If a class template has been declared, but not defined, at the point of instantiation (13.8.4.1 [temp.point]), the instantiation yields an incomplete class type (6.8 [basic.types]). [Example:

      template<class T> class X;
    
      X<char> ch;      // error: incomplete type X<char>
    

    end example] [Note: Within a template declaration, a local class (11.6 [class.local]) 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 causes the implicit instantiation of the declarations, but not...

  3. Delete 13.9.2 [temp.inst] paragraph 6, moving the note and example to paragraph 1 as shown above:

  4. A class template specialization is implicitly instantiated if the class type is used in a context that requires a completely-defined object type or if the completeness of the class type might affect the semantics of the program. [Note: In particular, if the semantics of an expression depend on the member or base class lists of a class template specialization, the class template specialization is implicitly generated. For instance, deleting a pointer to class type depends on whether or not the class declares a destructor, and conversion between pointer to class types depends on the inheritance relationship between the two classes involved. —end note] [Example:

      template<class T> class B { /* ... */ };
      template<class T> class D : public B<T> { /* ... */ };
    
      void f(void*);
      void f(B<int>*);
    
      void g(D<int>* p, D<char>* pp, D<double>* ppp) {
        f(p);            // instantiation of D<int> required: call f(B<int>*)
        B<char>* q = pp; // instantiation of D<char> required:
                         // convert D<char>* to B<char>*
        delete ppp;      // instantiation of D<double> required
    }
    

    end example]

  5. Change 13.9.2 [temp.inst] paragraph 7 as follows:

  6. If the function selected by overload resolution process (12.2 [over.match]) can determine the correct function to call be determined without instantiating a class template definition, it is unspecified whether that instantiation actually takes place. [Example:...
  7. Delete 13.9.2 [temp.inst] paragraphs 8-9:

  8. If an implicit instantiation of a class template specialization is required and the template is declared but not defined, the program is ill-formed. [Example:

      template<class T> class X;
    
      X<char> ch; // error: definition of X required
    

    end example]

    The implicit instantiation of a class template does not cause any static data members of that class to be implicitly instantiated.