This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

3228. Surprising variant construction

Section: [variant.ctor] Status: Resolved Submitter: Barry Revzin Opened: 2019-06-25 Last modified: 2020-11-09

Priority: 2

View other active issues in [variant.ctor].

View all other issues in [variant.ctor].

View all issues with Resolved status.


User mcencora on reddit today posted this example:

#include <variant>

struct ConvertibleToBool
  constexpr operator bool() const { return true; }

static_assert(std::holds_alternative<bool>(std::variant<int, bool>(ConvertibleToBool{})));

Before P0608, the variant holds bool. After P0608, the variant holds int so the static assertion fires.

I don't know what the right answer is between (a) ill-formed (b) hold bool and (c) hold int is, but I think (a) and (b) are better options than (c).

[2019-07 Issue Prioritization]

Priority to 2 after discussion on the reflector.

[This is US212; status set to "LEWG" for guidance on desired behavior.]

[2020-05-28; LEWG issue reviewing]

P1957R2 was accepted in Prague as CWG motion 5 and resolves LWG 3228.

[2020-11-09 Resolved for C++20. Status changed: Tentatively Resolved → Resolved.]


Resolved by P1957R2.

Proposed resolution: