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

Bugfixes for <any> #3965

Merged
merged 23 commits into from
Sep 21, 2023
Merged

Bugfixes for <any> #3965

merged 23 commits into from
Sep 21, 2023

Conversation

achabense
Copy link
Contributor

@achabense achabense commented Aug 14, 2023

This pr contains two fixes for std::any:

@achabense achabense requested a review from a team as a code owner August 14, 2023 12:08
@achabense achabense changed the title Bug fixes for <any> Bugfixes for <any> Aug 14, 2023
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Aug 14, 2023
@StephanTLavavej StephanTLavavej self-assigned this Aug 14, 2023
@achabense

This comment was marked as resolved.

stl/inc/any Outdated Show resolved Hide resolved
stl/inc/any Outdated
@@ -178,7 +177,7 @@ public:
int> = 0>
any& operator=(_ValueType&& _Value) {
// replace contained value with an object of type decay_t<_ValueType> initialized from _Value
*this = any{_STD forward<_ValueType>(_Value)};
_Assign(any{_STD forward<_ValueType>(_Value)});
Copy link
Contributor Author

@achabense achabense Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will hopefully not affect performance of operator=(const any&) and operator=(auto&&).
For operator=(any&&), it seems for correctness we have to make a local variable as well; otherwise the testcases introduced in 798e89c will be very hard to deal with.

@achabense
Copy link
Contributor Author

achabense commented Aug 20, 2023

static_assert(std::is_same<decltype(std::any_cast<int&&>(a)), int&&>::value, "");

I find some tests in P0220R1_any are actually ill-formed ~ an any& is not allowed to any_cast to an rvalue reference.

Though I think this should be well-formed; any_cast is performing static_cast, but the standard is requiring constructible instead of castable; I think this requirement is too restrictive.

@frederick-vs-ja
Copy link
Contributor

I find some tests in P0220R1_any are actually ill-formed ~ an any& is not allowed to any_cast to an rvalue reference.

Whether this case is ill-formed (currently) is unspecified - it's unspecified whether any violation of Mandates: is substitution failure when it can be. MSVC STL tends to make the ill-formedness SFINAE-unfriendly, which allows emitting informative message in static_assert.

stl/inc/any Outdated Show resolved Hide resolved
@@ -78,17 +78,17 @@ struct _Any_small_RTTI { // Hand-rolled vtable for nontrivial types that can be

template <class _Ty>
static void __CLRCALL_PURE_OR_CDECL _Destroy_impl(void* const _Target) noexcept {
_Destroy_in_place(*static_cast<_Ty*>(_Target));
_STD _Destroy_in_place(*static_cast<_Ty*>(_Target));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is combining unrelated fixes, which makes things harder to review and harder to investigate/revert when things go wrong. They're small enough that I don't think we need to request changes, but I wanted to mention this for the future.

In general, I would say that combining unrelated cleanups is less risky than combining fixes; we want to avoid grab-bag PRs either way, but when semantic changes are involved, we should be more disciplined.

@StephanTLavavej StephanTLavavej removed their assignment Sep 15, 2023
@StephanTLavavej StephanTLavavej self-assigned this Sep 20, 2023
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Copy link
Member

I had to push an additional commit to work around VSO-1659496 "/clr emits bogus error C2079 "uses undefined struct 'Incomplete'" despite std::variant's ADL defenses". Someday I'll remember this before preparing a merge.

@StephanTLavavej StephanTLavavej merged commit 4047639 into microsoft:main Sep 21, 2023
35 checks passed
@StephanTLavavej
Copy link
Member

⭐ 🐞 🛠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants