Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variant constructor and assignment shouldn't allow narrow conversion #463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tonyriviere88
Copy link

According to the standard, the constructor of a variant should construct a variant holding an alternative type T_i from an input of type T only if no narrow conversion is performed between T and T_i.

See documentation here: https://en.cppreference.com/w/cpp/utility/variant/variant
Constructor 4:

An overload F(T_i) is only considered if the declaration T_i x[] = { std::forward(t) }; is valid

As a direct consequence, the following code is valid (taken from the link above):

variant<float, long, double> z = 0; // OK, holds long
                                    // float and double are not candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant