Title
template-id as the declarator for a class template constructor
Status
cd3
Section
9.3.4 [dcl.meaning]
Submitter
Johannes Schaub

Created on 2011-12-24.00:00:00 last changed 131 months ago

Messages

Date: 2013-04-15.00:00:00

[Moved to DR at the April, 2013 meeting.]

Date: 2012-10-15.00:00:00

Proposed resolution (October, 2012):

  1. Change 9.3.4 [dcl.meaning] paragraph 1 as follows:

  2. A list of declarators appears after an optional (9.1 [dcl.pre]) decl-specifier-seq (9.2 [dcl.spec]). Each declarator contains exactly one declarator-id; it names the identifier that is declared. An unqualified-id occurring in a declarator-id shall be a simple identifier except for the declaration of some special functions (11.4.5 [class.ctor], 11.4.8 [class.conv], 11.4.7 [class.dtor], 12.4 [over.oper]) and for the declaration of template specializations or partial specializations (13.9 [temp.spec]). A declarator-id shall not...
  3. Change 11.4.5 [class.ctor] paragraph 1 as follows:

  4. Constructors do not have names. A special declarator syntax is used to declare or define the constructor. The syntax uses:

    • an optional decl-specifier-seq in which each decl-specifier is either a function-specifier or constexpr,

    • the constructor's class name, and

    • a parameter list

    in that order. In such a declaration, optional parentheses around the constructor class name are ignored. A declaration of a constructor uses a function declarator (9.3.4.6 [dcl.fct]) of the form

      ptr-declarator ( parameter-declaration-clause ) exception-specificationopt attribute-specifier-seqopt

    where the ptr-declarator consists solely of an id-expression, an optional attribute-specifier-seq, and optional surrounding parentheses, and the id-expression has one of the following forms:

    • in a member-declaration that belongs to the member-specification of a class but is not a friend declaration (11.8.4 [class.friend]), the id-expression is the injected-class-name (Clause 11 [class]) of the immediately-enclosing class;

    • in a member-declaration that belongs to the member-specification of a class template but is not a friend declaration, the id-expression is a class-name that names the current instantiation (13.8.3.2 [temp.dep.type]) of the immediately-enclosing class template; or

    • in a declaration at namespace scope or in a friend declaration, the id-expression is a qualified-id that names a constructor (6.5.5.2 [class.qual]).

    The class-name shall not be a typedef-name. In a constructor declaration, each decl-specifier in the optional decl-specifier-seq shall be friend, inline, explicit, or constexpr. [Example:...

  5. Delete 11.4.5 [class.ctor] paragraph 3:

  6. A typedef-name shall not be used as the class-name in the declarator-id for a constructor declaration.
  7. Change 11.4.5 [class.ctor] paragraph 4 as follows:

  8. A constructor shall not be virtual (11.7.3 [class.virtual]) or static (11.4.9 [class.static]). A constructor can be invoked for a const, volatile or const volatile object. A constructor shall not be declared const, volatile, or const volatile (_N4868_.11.4.3.2 [class.this]). const and volatile semantics (9.2.9.2 [dcl.type.cv]) are not applied on an object under construction. They come into effect when the constructor for the most derived object (6.7.2 [intro.object]) ends. A constructor shall not be declared with a ref-qualifier.
  9. Change 11.4.5 [class.ctor] paragraph 9 as follows:

  10. No return type (not even void) shall be specified for a constructor. A return statement in the body of a constructor shall not specify a return value. The address of a constructor shall not be taken.
  11. Change 11.4.7 [class.dtor] paragraphs 1-2 as follows:

  12. A special declarator syntax using an optional function-specifier (9.2.3 [dcl.fct.spec]) followed by ~ followed by the destructor's class name followed by an empty parameter list is used to declare the destructor in a class definition. In such a declaration, the ~ followed by the destructor's class name can be enclosed in optional parentheses; such parentheses are ignored. A typedef-name shall not be used as the class-name following the ~ in the declarator for a destructor declaration. A declaration of a destructor uses a function declarator (9.3.4.6 [dcl.fct]) of the form

      ptr-declarator ( parameter-declaration-clause ) exception-specificationopt attribute-specifier-seqopt

    where the ptr-declarator consists solely of an id-expression, an optional attribute-specifier-seq, and optional surrounding parentheses, and the id-expression has one of the following forms:

    • in a member-declaration that belongs to the member-specification of a class but is not a friend declaration (11.8.4 [class.friend]), the id-expression is ~class-name and the class-name is the injected-class-name (Clause 11 [class]) of the immediately-enclosing class;

    • in a member-declaration that belongs to the member-specification of a class template but is not a friend declaration, the id-expression is ~class-name and the class-name names the current instantiation (13.8.3.2 [temp.dep.type]) of the immediately-enclosing class template; or

    • in a declaration at namespace scope or in a friend declaration, the id-expression is nested-name-specifier ~class-name and the class-name names the same class as the nested-name-specifier.

    The class-name shall not be a typedef-name. A destructor shall take no arguments (9.3.4.6 [dcl.fct]). In a destructor declaration, each decl-specifier of the optional decl-specifier-seq shall be friend, inline, or virtual.

    A destructor is used to destroy objects of its class type. A destructor takes no parameters, and no return type can be specified for it (not even void). The address of a destructor shall not be taken. A destructor shall not be static. A destructor can be invoked for a const, volatile or const volatile object. A destructor shall not be declared const, volatile or const volatile (_N4868_.11.4.3.2 [class.this]). const and volatile semantics (9.2.9.2 [dcl.type.cv]) are not applied on an object under destruction. They stop being in effect when the destructor for the most derived object (6.7.2 [intro.object]) starts. A destructor shall not be declared with a ref-qualifier.

    This resolution also resolves issue 344.

Date: 2011-12-24.00:00:00

The status of a declaration like the following is unclear:

  template<typename T> struct A {
    A<T>();
  };

9.3.4 [dcl.meaning] paragraph 1 appears to say that it is not allowed, but it is not clear.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetstatus: ready -> dr
2012-11-03 00:00:00adminsetstatus: review -> ready
2012-09-24 00:00:00adminsetmessages: + msg3888
2012-02-27 00:00:00adminsetmessages: + msg3756
2012-02-27 00:00:00adminsetstatus: open -> review
2011-12-24 00:00:00admincreate