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

3228. Surprising variant construction

Section: 20.7.3.1 [variant.ctor] Status: LEWG Submitter: Barry Revzin Opened: 2019-06-25 Last modified: 2019-11-04

Priority: 2

View other active issues in [variant.ctor].

View all other issues in [variant.ctor].

View all issues with LEWG 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.]

Proposed resolution: