Fix EBO on std::optional and std::variant when targeting the MSVC ABI
authorEric Fiselier <eric@efcs.ca>
Fri, 28 Apr 2023 01:04:04 +0000 (21:04 -0400)
committerEric Fiselier <eric@efcs.ca>
Fri, 28 Apr 2023 01:04:04 +0000 (21:04 -0400)
commitdb381405ced7b65ad1cf8fc60bbdfb505e1ed3de
tree874e935e2500cb1d1def96e072446ab71e8d4301
parent47f72aede163348ee474be4a3004dc0a9195fa9c
Fix EBO on std::optional and std::variant when targeting the MSVC ABI

Committing on behalf of davidben. Reviewed as D146190

Patch originally by Jan Dörrie in https://reviews.llvm.org/D120064. I've just updated it to include tests, and update documentation that MSVC ABI is not stable.

In the current implementation both `std::optional` and `std::variant` don't perform the EBO on MSVC's ABI. This is because both classes inherit from multiple empty base classes, which breaks the EBO for MSVC. This patch fixes this issue by applying the `empty_bases` declspec attribute, which is already used to fix a similar issue for `std::tuple`.

See https://reviews.llvm.org/D120064 for discussion on MSVC ABI stability. From the discussion, libc++ doesn't have users that expect a stable ABI on MSVC. The fix is thus applied unconditionally to benefit more users. Documentation has been updated to reflect this.

Fixes https://github.com/llvm/llvm-project/issues/61095.
libcxx/docs/DesignDocs/ABIVersioning.rst
libcxx/docs/index.rst
libcxx/include/optional
libcxx/include/variant
libcxx/test/libcxx/utilities/optional/optional.object/optional_size.pass.cpp [new file with mode: 0644]
libcxx/test/libcxx/utilities/variant/variant.variant/variant_size.pass.cpp