[llvm] [ADT] Apply Rule of Five to StringTable::Iterator (PR #160815)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 23:37:38 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

StringTable::Iterator has a user-defined copy assignment operator, a
defaulted copy constructor, and a defaulted move constructor.

This patch makes the copy assignment operator defaulted and adds a
defaulted move assignment operator to adhere to the Rule of Five while
making the operators constexpr.


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


1 Files Affected:

- (modified) llvm/include/llvm/ADT/StringTable.h (+2-6) 


``````````diff
diff --git a/llvm/include/llvm/ADT/StringTable.h b/llvm/include/llvm/ADT/StringTable.h
index 575b3c929e40c..9422a6da1ce8e 100644
--- a/llvm/include/llvm/ADT/StringTable.h
+++ b/llvm/include/llvm/ADT/StringTable.h
@@ -118,12 +118,8 @@ class StringTable {
     constexpr Iterator(const Iterator &RHS) = default;
     constexpr Iterator(Iterator &&RHS) = default;
 
-    Iterator &operator=(const Iterator &RHS) {
-      Table = RHS.Table;
-      O = RHS.O;
-      S = RHS.S;
-      return *this;
-    }
+    constexpr Iterator &operator=(const Iterator &RHS) = default;
+    constexpr Iterator &operator=(Iterator &&RHS) = default;
 
     bool operator==(const Iterator &RHS) const {
       assert(Table == RHS.Table && "Compared iterators for unrelated tables!");

``````````

</details>


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


More information about the llvm-commits mailing list