WaldB
WaldB

Reputation: 1261

There seems to be a contradiction in §12.3.2/1 in the C++11 Standard

C++11 Standard §12.3.2/1 (emphasis mine):

A member function of a class X having no parameters with a name of the form

conversion-function-id:

operator conversion-type-id

conversion-type-id:

type-specifier-seq conversion-declarator

conversion-declarator:

ptr-operator conversion-declarator

specifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. No return type can be specified. If a conversion function is a member function, the type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id”.

Is a conversion function always a member function, or there are cases where this is not true?

Upvotes: 32

Views: 1851

Answers (2)

Casey
Casey

Reputation: 42594

The clause "If a conversion function is a member function," was added to the working draft in N2798 as part of the Concepts wording per N2773 Proposed Wording for Concepts. N2798 12.3.2/1 reads (I'll use bold to show additions, and strikeout to show removals):

1 A member function of a class X having no parameters, or an associated function of a concept whose sole parameter is of type X, with a name of the form

conversion-function-id:

operator conversion-type-id

conversion-type-id:

type-specifier-seq attribute-specifieropt conversion-declaratoropt

conversion-declarator:

ptr-operator conversion-declaratoropt

specifies a conversion from X to the type specified by the conversion-type-id. Such member functions are called conversion functions. Classes, enumerations, and typedef-names shall not be declared in the type-specifier-seq. Neither parameter types nor No return type can be specified. If a conversion function is a member function, tThe type of a the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id; if a conversion function is an associated function, the type of the conversion function is “function taking a parameter of type X returning conversion-type-id. A conversion function is never used to convert ...

The Concepts wording was removed in draft N2960. The "If a conversion function is a member function," should have also been removed at that time since it is now vestigal. Pertinent portion of N2960 §12.3.2/1:

1 A member function of a class X having no parameters, or an associated function of a concept whose sole parameter is of type X, with a name of the form

conversion-function-id:

operator conversion-type-id

conversion-type-id:

type-specifier-seq attribute-specifieropt conversion-declaratoropt

conversion-declarator:

ptr-operator conversion-declaratoropt

specifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. No return type can be specified. If a conversion function is a member function, the type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id; if a conversion function is an associated function, the type of the conversion function is “function taking a parameter of type X returning conversion-type-id. ...

2018-02-03 Update: This has been fixed in C++17

CWG corrected this wording as a drive-by while fixing CWG issue 1990.

Upvotes: 47

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145457

A conversion function is always a (non-static) member function.

The "if" wording was not present in C++98 or C++03. I can find no reference to it in the defect reports list either. It's strange.


As R. Martinho Fernandes commented the wording is strange, but not contradictory.

Upvotes: 6

Related Questions