-
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
<xutility>
: SFINAE constraint on construct_at
prevents emplacing immovable objects with copy elision
#2620
Comments
Originally we had it constrained via a requires clause, but that lead to some strange compiler errors for some corner cases. (Not to speak of intellisense which is EDG based and thus currently not available for concepts) @StephanTLavavej found this to be the appropriate perma workaround. Do you still remember what broke? |
Oh and it is constexpr container support machinery. Who would have thought? Fixed by 075dfaf I see that the original bug was fixed, so maybe we can go back to the proper constraint? |
Also please note, that your code exhibits a certain amount of UB, because you are taking the reference to a not yet alive object. std::construct_at(&u.s, copy_elider{}); here |
Yes, I'm aware of the potential UB. It's just that I couldn't come up with any concise examples without UB 😭 |
No, this is well-defined, as at least the code is just taking the address of an inactive member. If such code has UB, then we can't generally reasonably change active member of a union during constant evaluation. Using |
Ahh, sorry, you are correct, you can take the address. https://godbolt.org/z/zbbWPr3M3 The issue I was miss-remembering was that we passed that address on into another function (char_traits for std::string) and there it is indeed invalid. |
I saw the same error there: DevCom-1691516 and I think it might be a compiler issue. |
Agreed that this seems like a compiler issue if it works fine with Clang and MSVC's STL (haven't confirmed), labeling accordingly. |
It seems that MSVC works if implementation of the constraint is changed to: void_t<decltype(::new (_STD declval<void*>()) _Ty(_STD declval<_Types>()...))>* = nullptr |
@frederick-vs-ja you are correct C1XX and Clang work with your solution but unfortunately EDG doesn't work with both constraints (your and initial) :( Do you think we need to somehow reduce the example or just report it as it is to DevCom? |
I think we should report that issue for EDG and work around it by keeping the original code for EDG with |
Describe the bug
Currently the constraint on
construct_at
is implemented via SFINAESTL/stl/inc/xutility
Lines 132 to 134 in f099e9c
This causes an error when trying to emplace immovable objects with copy elision:
xutility(145): error C2783: '_Ty *std::construct_at(_Ty *const ,_Types &&...) noexcept(<expr>)': could not deduce template argument for '<unnamed-symbol>'
Example code:
Yet if the constraint is implemented via concepts, i.e.
then the example code above works as expected. I don't know the reason that these two behaviors differ though...
This issue hinders the ability to emplace immovable objects into
optional
s orvariant
s using the copy elision converter trick shown above.STL version
VS Community 2022, Version 17.1.2
The text was updated successfully, but these errors were encountered: