================
@@ -15383,6 +15401,31 @@ static void diagnoseDeprecatedCopyOperation(Sema &S,
CXXMethodDecl *CopyOp) {
}
}
+// A defaulted copy or move assignment operator for a union copies the object
+// representation as if by a memcpy, the same way the defaulted union copy
+// constructor does. The memberwise loops in DefineImplicitCopyAssignment and
+// DefineImplicitMoveAssignment skip union members, so the whole-object copy is
+// emitted here instead. Marks AssignOp invalid and returns false on failure.
+static bool buildUnionAssignmentCopy(Sema &S, SourceLocation Loc,
+ CXXRecordDecl *ClassDecl,
+ std::optional<RefBuilder> &ExplicitObject,
+ std::optional<DerefBuilder> &DerefThis,
+ const ExprBuilder &From,
+ CXXMethodDecl *AssignOp,
+ SmallVectorImpl<Stmt *> &Statements) {
+ ExprBuilder &To = ExplicitObject ? static_cast<ExprBuilder
&>(*ExplicitObject)
+ : static_cast<ExprBuilder &>(*DerefThis);
+ StmtResult Copy = buildMemcpyForAssignmentOp(
----------------
erichkeane wrote:
> One thing we should pay attention to are warning counts (this may be a total
> non-issue, btw): we should make sure that the final count the user sees does
> not include these ignored warnings. I don't _think_ they will, but something
> to spot-check.
I tested that `setIgnoreAllWarnings` DOES prevent the warning count from being
incremented. I ran this test:
https://godbolt.org/z/c15Kvj5vc
See how it has 3 diagnostics.
I then wrapped the 'missing prototype' warning in setIgnoreAllWarnings calls,
and ran it again:
```
ekeane@dev-epyc4:/local/home/ekeane/llvm-project/build/bin$ git diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f56f1ab04e49..9a8013de9a5b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16904,7 +16904,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt
*Body, bool IsInstantiation,
// global functions that fail to be declared in header files.
const FunctionDecl *PossiblePrototype = nullptr;
if (ShouldWarnAboutMissingPrototype(FD, PossiblePrototype)) {
+ getDiagnostics().setIgnoreAllWarnings(true);
Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;
+ getDiagnostics().setIgnoreAllWarnings(false);
if (PossiblePrototype) {
// We found a declaration that is not a prototype,
ekeane@dev-epyc4:/local/home/ekeane/llvm-project/build/bin$ ./clang -cc1
temp.cpp -Weverything
temp.cpp:2:1: warning: non-void function does not return a value [-Wreturn-type]
2 | }
| ^
1 warning generated.
```
Note now only `1 warning generated`.
Vs without the 'diff' above:
```
ekeane@dev-epyc4:/local/home/ekeane/llvm-project/build/bin$ ./clang -cc1
temp.cpp -Weverything
temp.cpp:1:5: warning: no previous prototype for function 'baz'
[-Wmissing-prototypes]
1 | int baz() {
| ^
temp.cpp:1:1: note: declare 'static' if the function is not intended to be used
outside of this translation unit
1 | int baz() {
| ^
| static
temp.cpp:2:1: warning: non-void function does not return a value [-Wreturn-type]
2 | }
| ^
temp.cpp:10:6: warning: no previous prototype for function 'fold_constant_load'
[-Wmissing-prototypes]
10 | void fold_constant_load() {
| ^
temp.cpp:10:1: note: declare 'static' if the function is not intended to be
used outside of this translation unit
10 | void fold_constant_load() {
| ^
| static
3 warnings generated.
```
SO, Sanity check complete :)
https://github.com/llvm/llvm-project/pull/206579
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits