This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Accepted as a DR at the November, 2018 (San Diego) meeting.]
According to 12.2.2.6 [over.match.conv] paragraph 1, when a classtypeS is used as an initializer for an object of typeT,
The conversion functions ofS and its base classes areconsidered. Those non-explicit conversion functions that are not hiddenwithinS and yield typeT or a type that can be convertedto typeT via a standard conversion sequence(12.2.4.2.2 [over.ics.scs]) are candidate functions.
Because conversion fromstd::nullptr_t toboolis only permitted in direct-initialization (7.3.14 [conv.fctptr]),it is not clear whether there is a standard conversion sequence fromstd::nullptr_t tobool, considering that animplicit conversion sequence is intended to modelcopy-initialization. Should 12.2.2.6 [over.match.conv] beunderstood to refer only to conversions permitted incopy-initialization, or should the form of the initialization beconsidered? 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 bearon the intent (or, alternatively, might describe a situation thatcannot arise):
A conversion that does not convert a pointer, a pointer to member, orstd::nullptr_t tobool is better than one that does.
Proposed resolution (June, 2018):
Change 7.3.15 [conv.bool] paragraph 1 as follows:
A prvalue of arithmetic, unscoped enumeration, pointer, orpointer-to-member type can be converted to a prvalue of typebool. A zero value, null pointer value, or null memberpointer value is converted tofalse; any other value isconverted totrue.For direct-initialization(9.5 [dcl.init]), a prvalue of typestd::nullptr_t can be converted to a prvalue oftypebool; the resulting value isfalse.
Add the following bullet before 9.5 [dcl.init]bullet 17.8:
The semantics of initializers are as follows. Thedestination type is the type of the object orreference being initialized and thesource type isthe type of the initializer expression. If the initializeris not a single (possibly parenthesized) expression, thesource type is not defined.
...
Otherwise, if the initialization isdirect-initialization, the source typeisstd::nullptr_t, and the destination typeisbool, the initial value of the object beinginitialized isfalse.
Otherwise, the initial value of the object beinginitialized is the (possibly converted) value...
Change 12.2.4.3 [over.ics.rank] bullet 4.1 as follows:
Standard conversion sequences are ordered by their ranks: anExact Match is a better conversion than a Promotion, whichis a better conversion than a Conversion. Two conversionsequences with the same rank are indistinguishable unlessone of the following rules applies:
A conversion that does not convert apointer
,or a pointer to member,orstd::nullptr_ttobool is betterthan one that does....
This resolution also resolvesissue 2133.