-
Notifications
You must be signed in to change notification settings - Fork 71
Fix Variant #768
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
Open
sfod
wants to merge
34
commits into
main
Choose a base branch
from
fix-variant
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix Variant #768
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
This PR resolves two issues with Crt::Variant.
Issue 1. Compilation error on Windows platform when an underlying type has special function member(s) deleted
When building shared libraries on Windows platform, we add
__declspec(dllexport)
attribute to class definitions. MS docs say the following:This means that compiler will try to generate special function members whenever possible because it doesn't know which members a user of a .dll will use. Whether the compiler generates a special member function depends on 1) if base classes have this special member function and 2) member fields have this special member function.
The issue with
Crt::Variant
is that all its special member functions are defined as if the underlying types always support copying and moving (for copy constructor example, see 1 and 2). Consequently, the compiler attempts to generate all special member functions for the user class, resulting in compilation error:See a CI run where new tests failed and a godbolt snippet demonstrating the issue.
Issue 2. Compilation error on old gcc compilers when a user class constructor has noexcept specifier
Constructors in
Crt::Variant
doesn't have noexcept specifier. When a user class tries to addnoexcept
, it causes compilation error on older gcc compilers:This stopped to be an error in gcc 10.
Description of changes:
The first problem can be resolved by removing user-defined special members from
Crt::Variant
. Move all implementation details intoVariantImpl
, withVariant
members delegating work toVariantImpl
.The special members in
Variant
will be either defaulted or deleted based on the underlying type traits. This is achieved by inheriting from auxiliary classes that have appropriately defaulted or deleted special members.This issue can also be resolved by explicitly deleting special members in user classes. However, this approach is inconvenient for Crt::Variant users. Therefore, if cleaner solution exists, it should be implemented instead.
Add
noexcept
specifier to theCrt::Variant
constructors based on the underlying type traits.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.