[llvm] f3390fc - [EquivClasses] Fix signature of copy-assignment operator (#130140)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 8 01:38:51 PST 2025


Author: Ramkumar Ramachandra
Date: 2025-03-08T09:38:47Z
New Revision: f3390fca034d2762f87ac8057078d6e9661305ce

URL: https://github.com/llvm/llvm-project/commit/f3390fca034d2762f87ac8057078d6e9661305ce
DIFF: https://github.com/llvm/llvm-project/commit/f3390fca034d2762f87ac8057078d6e9661305ce.diff

LOG: [EquivClasses] Fix signature of copy-assignment operator (#130140)

The current signature is unusual, and deviates from the C++ operator
overloading spec.

https://en.cppreference.com/w/cpp/language/copy_assignment

Added: 
    

Modified: 
    llvm/include/llvm/ADT/EquivalenceClasses.h
    llvm/unittests/ADT/EquivalenceClassesTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/EquivalenceClasses.h b/llvm/include/llvm/ADT/EquivalenceClasses.h
index 4f98b84cf97d2..c375d6e77b12a 100644
--- a/llvm/include/llvm/ADT/EquivalenceClasses.h
+++ b/llvm/include/llvm/ADT/EquivalenceClasses.h
@@ -144,7 +144,7 @@ class EquivalenceClasses {
     operator=(RHS);
   }
 
-  const EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
+  EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
     TheMapping.clear();
     for (iterator I = RHS.begin(), E = RHS.end(); I != E; ++I)
       if (I->isLeader()) {

diff  --git a/llvm/unittests/ADT/EquivalenceClassesTest.cpp b/llvm/unittests/ADT/EquivalenceClassesTest.cpp
index 70e161a03d988..bfb7c8d185fc8 100644
--- a/llvm/unittests/ADT/EquivalenceClassesTest.cpp
+++ b/llvm/unittests/ADT/EquivalenceClassesTest.cpp
@@ -13,6 +13,15 @@ using namespace llvm;
 
 namespace llvm {
 
+TEST(EquivalenceClassesTest, CopyAssignemnt) {
+  EquivalenceClasses<int> EC, Copy;
+  EC.insert(1);
+  EC.insert(4);
+  EquivalenceClasses<int> &Ref = Copy = EC;
+  EXPECT_EQ(Copy.getNumClasses(), 2u);
+  EXPECT_EQ(&Ref, &Copy);
+}
+
 TEST(EquivalenceClassesTest, NoMerges) {
   EquivalenceClasses<int> EqClasses;
   // Until we merged any sets, check that every element is only equivalent to


        


More information about the llvm-commits mailing list