[clang] Guard against self-assignment; NFC (PR #145743)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 25 10:28:21 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

<details>
<summary>Changes</summary>

This was caught by a static analysis tool and seemed like a reasonable code quality improvement.

---
Full diff: https://github.com/llvm/llvm-project/pull/145743.diff


1 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+5-3) 


``````````diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 24f3ae78e857b..f4d39afded322 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6410,9 +6410,11 @@ class SpirvOperand {
   ~SpirvOperand() {}
 
   SpirvOperand &operator=(const SpirvOperand &Other) {
-    this->Kind = Other.Kind;
-    this->ResultType = Other.ResultType;
-    this->Value = Other.Value;
+    if (this != &Other) {
+      this->Kind = Other.Kind;
+      this->ResultType = Other.ResultType;
+      this->Value = Other.Value;
+    }
     return *this;
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/145743


More information about the cfe-commits mailing list