CWG Issue 1435 (original) (raw)
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 orconstexpr,the constructor's class name, anda 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, orconstexpr. [Example:...
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 bestatic. A destructor can be invoked for aconst, volatile or const volatileobject. 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.8.2 [intro.object]) starts. A destructor shall not be declared with a_ref-qualifier_.