C++ Logo

std-discussion

Advanced search

P0608 seems to have unintended consequences - variant vs overload resolution

From: Tjernstrom, Staffan <Staffan.Tjernstrom_at_[hidden]>
Date: Wed, 12 Jun 2019 13:41:35 +0000
P0608r3, as adopted in San Diego 2018, addresses several surprising type conversion choices that occur during overload resolution in the use of std::variant.

However, that has led to a split between how things end up working between "classic" overload resolution, and overload resolution for std::variant. It feels like this was not the intent, and certainly leads to a how-to-teach problem.

For instance.


Before P0608 - behaviour is consistent, but surprising

int func( string )
{
   return 42;
}

int func( bool )
{
   return 19;
}

int x = func( "Hello" ); // x is 19
int y= func( "Hello"s ); // x is 42

std::variant< bool, string > z;
z = "Hello World"; // z holds a bool

Now, with P0608 in place, we have conflicting behaviour, but the variant case is "sane".
int func( string )
{
   return 42;
}

int func( bool )
{
   return 19;
}

int x = func( "Hello" ); // x is 19
int y= func( "Hello"s ); // x is 42

std::variant< bool, string > z;
z = "Hello World"; // z holds a string

Given where we are in the cycle, I don't know if the correct thing to do is to suggest that we fix the core language, undo P0608, do nothing, or some fourth option.

Kind Rgds
Staffan Tj.


________________________________

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Received on 2019-06-12 08:43:24