-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Fix false positive of [[clang::require_explicit_initialization]] on copy/move constructors #126553
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
Conversation
@llvm/pr-subscribers-clang Author: None (higher-performance) ChangesFixes #126490 Full diff: https://github.com/llvm/llvm-project/pull/126553.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 308222a79d920c7..18090eb1c9e9ac9 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4576,7 +4576,9 @@ static void TryConstructorInitialization(Sema &S,
if (!IsListInit &&
(Kind.getKind() == InitializationKind::IK_Default ||
Kind.getKind() == InitializationKind::IK_Direct) &&
- DestRecordDecl != nullptr && DestRecordDecl->isAggregate() &&
+ DestRecordDecl != nullptr &&
+ !(CtorDecl->isCopyOrMoveConstructor() && CtorDecl->isImplicit()) &&
+ DestRecordDecl->isAggregate() &&
DestRecordDecl->hasUninitializedExplicitInitFields()) {
S.Diag(Kind.getLocation(), diag::warn_field_requires_explicit_init)
<< /* Var-in-Record */ 1 << DestRecordDecl;
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp
index 7578b288d7b3fe7..6565bf31e05d72b 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -1582,7 +1582,21 @@ void aggregate() {
F("___"),
F("____")
};
- (void)ctors;
+
+ struct Copy {
+ Embed e;
+ EmbedDerived ed;
+ F f;
+ Copy(const Copy &c) : e(c.e), ed(c.ed), f(c.f) {} // no-error
+ };
+ F copy1(ctors[0]); // no-error
+ (void)copy1;
+ F copy2{ctors[0]}; // no-error
+ (void)copy2;
+ F copy3 = ctors[0]; // no-error
+ (void)copy3;
+ F copy4 = {ctors[0]}; // no-error
+ (void)copy4;
S::foo(S{1, 2, 3, 4});
S::foo(S{.s1 = 100, .s4 = 100});
|
@AaronBallman could we get this in for LLVM 20? |
a15c83c
to
dc5d3ea
Compare
…opy/move constructors Fixes llvm#126490
dc5d3ea
to
dd55dd1
Compare
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.
LGTM, but waiting for @hokein to have a chance to approve as well.
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.
I verified all compilations failures related to #126490 we found so far, and they are all fixed by this PR. Thanks!
thank you! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/15558 Here is the relevant piece of the build log for the reference
|
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.
Thanks for the quick fix.
@@ -4576,7 +4576,9 @@ static void TryConstructorInitialization(Sema &S, | |||
if (!IsListInit && |
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.
nit: I think this if condition is becoming complex enough that it's worth adding a comment for explanation.
Oh - @AaronBallman would you mind tagging this for the release so we can cherry pick? |
Sure! |
/cherry-pick 90192e8 |
/pull-request #126767 |
…opy/move constructors (llvm#126553) Fixes llvm#126490 (cherry picked from commit 90192e8)
…opy/move constructors (llvm#126553) Fixes llvm#126490
…opy/move constructors (llvm#126553) Fixes llvm#126490
…opy/move constructors (llvm#126553) Fixes llvm#126490
Fixes #126490