Title
Surprising variant construction
Status
new
Section
[variant.ctor]
Submitter
Barry Revzin

Created on 2019-06-25.00:00:00, last changed 2019-07-23.15:26:26.

Messages

Date: 2019-07-23.15:26:26

[ 2019-07 Issue Prioritiztion ]

Priority to 2 after discussion on the reflector.

Date: 2019-06-25.00:00:00

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

History
Date User Action Args
2019-07-23 15:26:26adminsetmessages: + msg10509
2019-06-25 00:00:00admincreate