Title
Declarator operators and conversion function
Status
cd6
Section
11.4.8.3 [class.conv.fct]
Submitter
James Widman

Created on 2013-08-02.00:00:00 last changed 20 months ago

Messages

Date: 2021-12-15.00:00:00

Proposed resolution (December, 2021):

Change 11.4.8.3 [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

    conversion-function-id:
      operator conversion-type-id
    conversion-type-id:
      type-specifier-seq conversion-declaratoropt
    conversion-declarator:
      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 (9.3.4.6 [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 (9.3.4.6 [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: 2022-02-15.00:00:00

[Accepted at the February, 2022 meeting.]

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.

History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: dr -> cd6
2022-02-15 00:00:00adminsetstatus: ready -> dr
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