Declarator operators and conversion function
Section [class.conv.fct]
James Widman

Created on 2013-08-02.00:00:00 last changed 3 weeks ago


Date: 2021-12-15.00:00:00

Proposed resolution (December, 2021):

Change [class.conv.fct] paragraph 1 as follows, splitting the paragraph as indicated:

A member function of a class X with a name of the form

      operator conversion-type-id
      type-specifier-seq conversion-declaratoropt
      ptr-operator conversion-declaratoropt

A declaration whose declarator-id has an unqualified-id that is a conversion-function-id declares a conversion function; its declarator shall be a function declarator ( [dcl.fct]) of the form

    ptr-declarator ( parameter-declaration-clause ) cv-qualifier-seqopt
      ref-qualifier-seqopt noexcept-specifieropt 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 or class template but is not a friend declaration (11.8.4 [class.friend]), the id-expression is a conversion-function-id;

  • otherwise, the id-expression is a qualified-id whose unqualified-id is a conversion-function-id.

A conversion function shall have no parameters and shall be a non-static member function of a class or class template X; it specifies a conversion from X to the type specified by the conversion-type-id, interpreted as a type-id (9.3.2 [dcl.name]). Such functions are called conversion functions.

A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall not be neither a defining-type-specifier nor static. The type of the conversion function ( [dcl.fct]) is “noexceptopt function taking no parameter cv-qualifier-seqopt ref-qualifieropt returning conversion-type-id”.

A conversion function is never used to convert a (possibly cv-qualified) object to the (possibly cv-qualified) same object type (or a reference to it), to a (possibly cv-qualified) base class of that type (or a reference to it), or to cv void.102 [Example 1:...

Date: 2013-08-02.00:00:00

Presumably the following example is intended to be ill-formed:

  struct A {
    (*operator int*());
  A a;
  int *x = a; // Ok?

It is not clear, however, which rule is supposed to reject such a member-declaration.

Date User Action Args
2022-01-06 00:00:00adminsetmessages: + msg6600
2022-01-06 00:00:00adminsetstatus: drafting -> ready
2013-10-14 00:00:00adminsetstatus: open -> drafting
2013-08-02 00:00:00admincreate