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

Created on 2019-06-25.00:00:00 last changed 49 months ago

Messages

Date: 2020-11-09.22:09:58
Resolved by

Rationale:

P1957R2.
Date: 2020-11-09.00:00:00

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

Date: 2020-05-15.00:00:00

[ 2020-05-28; LEWG issue reviewing ]

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

Date: 2019-11-04.18:05:33

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

Date: 2019-08-23.18:06:54

[ 2019-07 Issue Prioritization ]

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
2020-11-09 22:09:58adminsetmessages: + msg11602
2020-05-31 09:54:47adminsetmessages: + msg11318
2020-05-31 09:54:47adminsetmessages: + msg11317
2020-05-31 09:54:47adminsetstatus: lewg -> resolved
2019-11-04 18:05:33adminsetmessages: + msg10731
2019-11-04 18:05:33adminsetstatus: new -> lewg
2019-07-23 15:26:26adminsetmessages: + msg10509
2019-06-25 00:00:00admincreate