-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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>
: variant::operator=(T&&)
accept wrong case
#2171
Comments
<variant>
: The implementation of variant::operator=(T&&)
seems to be wrong<variant>
: variant::operator=(T&&)
accept wrong case?
<variant>
: variant::operator=(T&&)
accept wrong case?<variant>
: variant::operator=(T&&)
accept wrong case
This is not the result of a bug, this is an intentional behavior change from C++20 (via WG21-P0608) that we do not implement in earlier language modes due to the potential for breakage. In C++20, [variant.assign]/11 determines the alternative type
When A x[] = { std::forward<A>(t) }; is ill-formed since B x[] = { std::forward<A>(t) }; is well-formed. Consequently, the imaginary overload set only contains (I suspect libstdc++ hasn't implemented this C++20 change yet, but on the off chance it's a bug let's tag @jwakely.) |
P0608 was implemented for GCC 10.1, but is enabled unconditionally for C++17 and C++20. |
I think you have a bug in your assignment operator, then. Interestingly, the converting constructor seems to do the right thing : https://godbolt.org/z/rxTGPzcx9. |
I don't understand. Under your description,
|
https://cplusplus.github.io/LWG/issue3585 says that libstdc++ is correctly implementing what the standard requires, warts and all. |
Thank you @hewilk for pointing out that the wording doesn't say what I want it to say despite my determined efforts to be unteachable, and thank you @jwakely for filing this LWG issue to keep |
I think this issue was submitted by @brevzin, thank you. |
This seems fixed since LWG-3585 has been voted into the Working Paper... |
From [variant#assign-13] (emphasis mine):
For the last case, MSVC STL did not call
operator=(variant(std::forward<T>(t)))
but called_Emplace_valueless<_TargetIdx>(_STD move(_Temp))
:STL/stl/inc/variant
Lines 1068 to 1093 in 78ff461
Consider (godbolt):
In this case,
_Variant_should_directly_construct_v
(that is,is_nothrow_constructible_v<B, A> || !is_nothrow_move_constructible_v<B>
) is false, so we calloperator=(variant&&)
, but sinceA
's move constructor is deleted, we should fail.Please note that MSVC v19.28 and v19.29 under
/std:c++17
correctly rejected it, so I don't know where the problem is (it seems to be in 87152f4).The text was updated successfully, but these errors were encountered: