Repository navigation
Masked copy/move functions affecting trivial copyability [GH #628] #629
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
daveedvdv-nvidia
wants to merge
1
commit into
main
Choose a base branch
from
fix/628
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.
+406
−105
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
src/pending_changes/gh-628-masked-copy-functions-triviality.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [GH #628] | ||
| Masked copy/move functions affecting trivial copyability | ||
|
|
||
| A copy/move constructor or assignment operator that is masked by a more | ||
| constrained one of the same kind is not "eligible", and it should therefore | ||
| not affect whether the class is trivially copyable. However, two cases were | ||
| previously handled incorrectly. First, the masking check compared the | ||
| complete function types, so a difference in exception specifications kept a | ||
| function from being masked. Second, a masked user-provided function of a base | ||
| class or member made the corresponding implicit function of the enclosing | ||
| class nontrivial, even though it is not selected to copy or move the subobject. | ||
| For example, with --c++20: | ||
|
|
||
| template<typename T> struct S { | ||
| S(const S&) noexcept {} | ||
| S(const S&) requires true = default; | ||
| }; | ||
| static_assert(__is_trivially_copyable(S<int>)); // Previously failed. | ||
| template<typename T> struct B { | ||
| B(B&&); | ||
| B(B&&) requires true = default; | ||
| }; | ||
| struct D : B<int> {}; | ||
| static_assert(__is_trivially_copyable(D)); // Previously failed. | ||
|
|
||
| The GNU library's std::optional uses this pattern. Also, a copy/move | ||
| assignment operator whose constraints are not satisfied no longer keeps a | ||
| class from being trivially copyable, and the constraints of constructors that | ||
| are not copy/move constructors are no longer checked to determine that. |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Masked-copy gate can make a derived copy constructor trivial when a template is selected.
When a base's non-template copy constructor is ineligible (for example,
requires false) and a constructor template is selected to copy the base, the derived class's implicit copy constructor is still marked trivial. Before this change, the base's user-provided copy constructor setmakes_copy_construction_nontrivial, and that flag propagated to the derived class. The selected template is user-provided and nontrivial, so the derived copy constructor must not be trivial.The copy-subobject path in
check_base_or_mbr_class_type_for_suppressionrecords only constexpr status for the selected constructor (src/class_decl.c:22775-22785). The move path records nontriviality for the same case (src/class_decl.c:22807-22814). Apply the same rule to the copy path:Record nontrivial copy construction for a selected subobject constructor
} else if (rout_sym != NULL) { rout_sym = fundamental_symbol_of(rout_sym); if (symbol_is(rout_sym, sk_member_function)) { a_routine_ptr rp = rout_sym->variant.routine.ptr; + if (!rp->is_trivial_copy_function) { + class_symbol_supp(symbol_for(class_type)) + ->makes_copy_construction_nontrivial = TRUE; + } /* if */ if (!rp->is_constexpr) {The masked-function exception in
user_provided_copy_functions_are_maskedshould not suppress a selected nontrivial subobject constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, but slightly differently: The copy constructor case now records a selected constructor that is user-provided, rather than any nontrivial one.
makes_copy_construction_nontrivialdeliberately doesn't reflect nontriviality caused by a virtual function table (the enclosing class has one too), and__is_bitwise_cloneablerelies on that. With the suggested!rp->is_trivial_copy_function,imported/clang/cpp/SemaCXX/ptrauth-type-traitsgot four false failures for classes with polymorphic bases. We now have regression tests for this also.