CWG Issue 1781 (original) (raw)

This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


1781. Converting from nullptr_t to bool in overload resolution

Section: 12.2.2.6 [over.match.conv]Status: CD5Submitter: Hubert TongDate: 2013-09-26

[Accepted as a DR at the November, 2018 (San Diego) meeting.]

According to 12.2.2.6 [over.match.conv] paragraph 1, when a class type S is used as an initializer for an object of type T,

The conversion functions of S and its base classes are considered. Those non-explicit conversion functions that are not hidden within S and yield type T or a type that can be converted to type T via a standard conversion sequence (12.2.4.2.2 [over.ics.scs]) are candidate functions.

Because conversion from std::nullptr_t to boolis only permitted in direct-initialization (7.3.14 [conv.fctptr]), it is not clear whether there is a standard conversion sequence fromstd::nullptr_t to bool, considering that an implicit conversion sequence is intended to model copy-initialization. Should 12.2.2.6 [over.match.conv] be understood to refer only to conversions permitted in copy-initialization, or should the form of the initialization be considered? For example,

struct SomeType { operator std::nullptr_t(); }; bool b{ SomeType() }; // Well-formed?

Note also 12.2.4.3 [over.ics.rank] paragraph 4, which may bear on the intent (or, alternatively, might describe a situation that cannot arise):

A conversion that does not convert a pointer, a pointer to member, orstd::nullptr_t to bool is better than one that does.

See also issues 2133 and2243.)

Proposed resolution (June, 2018):

  1. Change 7.3.15 [conv.bool] paragraph 1 as follows:

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer-to-member type can be converted to a prvalue of typebool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true. For direct-initialization (9.5 [dcl.init]), a prvalue of typestd::nullptr_t can be converted to a prvalue of type bool; the resulting value is false.

  1. Add the following bullet before 9.5 [dcl.init] bullet 17.8:

The semantics of initializers are as follows. The_destination type_ is the type of the object or reference being initialized and the source type is the type of the initializer expression. If the initializer is not a single (possibly parenthesized) expression, the source type is not defined.

  1. Change 12.2.4.3 [over.ics.rank] bullet 4.1 as follows:

Standard conversion sequences are ordered by their ranks: an Exact Match is a better conversion than a Promotion, which is a better conversion than a Conversion. Two conversion sequences with the same rank are indistinguishable unless one of the following rules applies:

This resolution also resolves issue 2133.