Movatterモバイル変換


[0]ホーム

URL:


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


1781. Converting fromnullptr_t tobool in overload resolution

Section:12.2.2.6  [over.match.conv]    Status:CD5    Submitter:Hubert Tong    Date: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 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.

See also issues2133 and2243.)

Proposed resolution (June, 2018):

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

  2. 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.
  3. Add the following bullet before 9.5 [dcl.init]bullet 17.8:

  4. 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.

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

  6. 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:

This resolution also resolvesissue 2133.




[8]ページ先頭

©2009-2026 Movatter.jp