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

3228. Surprising variant construction

Section: 20.7.3.1 [variant.ctor] Status: Tentatively Resolved Submitter: Barry Revzin Opened: 2019-06-25 Last modified: 2020-05-31

Priority: 2

View other active issues in [variant.ctor].

View all other issues in [variant.ctor].

View all issues with Tentatively Resolved status.

Discussion:

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.

Rationale:

Resolved by P1957R2.

Proposed resolution: