Skip to content

Commit 5f5b24f

Browse files
committed
[C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator with its arguments reversed to ease commutativity. This reversed version is ambiguous with the hand-written operator when the argument is const but `this` isn't.
1 parent cbf9694 commit 5f5b24f

File tree

12 files changed

+18
-18
lines changed

12 files changed

+18
-18
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,8 @@ class SDKNodeVectorViewer::ViewerIterator {
536536
ViewerIterator(const ViewerIterator& mit) : Viewer(mit.Viewer), P(mit.P) {}
537537
ViewerIterator& operator++();
538538
ViewerIterator operator++(int) {ViewerIterator tmp(*this); operator++(); return tmp;}
539-
bool operator==(const ViewerIterator& rhs) {return P==rhs.P;}
540-
bool operator!=(const ViewerIterator& rhs) {return P!=rhs.P;}
539+
bool operator==(const ViewerIterator& rhs) const {return P==rhs.P;}
540+
bool operator!=(const ViewerIterator& rhs) const {return P!=rhs.P;}
541541
const NodePtr& operator*() {return *P;}
542542
};
543543

include/swift/AST/ArgumentList.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ class Argument final {
9595
/// Whether the argument is a compile-time constant value.
9696
bool isConst() const;
9797

98-
bool operator==(const Argument &other) {
98+
bool operator==(const Argument &other) const {
9999
return LabelLoc == other.LabelLoc && Label == other.Label &&
100100
ArgExpr == other.ArgExpr;
101101
}
102-
bool operator!=(const Argument &other) { return !(*this == other); }
102+
bool operator!=(const Argument &other) const { return !(*this == other); }
103103
};
104104

105105
/// Represents the argument list of a function call or subscript access.

include/swift/IDE/Utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ struct DeclaredDecl {
412412
bool ReferredAfterRange;
413413
DeclaredDecl(ValueDecl* VD) : VD(VD), ReferredAfterRange(false) {}
414414
DeclaredDecl(): DeclaredDecl(nullptr) {}
415-
bool operator==(const DeclaredDecl& other);
415+
bool operator==(const DeclaredDecl& other) const;
416416
};
417417

418418
struct ReferencedDecl {

include/swift/RemoteInspection/TypeRef.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TypeRefID {
120120
};
121121

122122

123-
bool operator==(const TypeRefID &Other) {
123+
bool operator==(const TypeRefID &Other) const {
124124
return Bits == Other.Bits;
125125
}
126126
};

include/swift/SIL/SILInstruction.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ class SILInstructionResultArray {
260260
llvm::mapped_iterator<iterator, SILType(*)(SILValue), SILType>>;
261261
type_range getTypes() const;
262262

263-
bool operator==(const SILInstructionResultArray &rhs);
264-
bool operator!=(const SILInstructionResultArray &other) {
263+
bool operator==(const SILInstructionResultArray &rhs) const;
264+
bool operator!=(const SILInstructionResultArray &other) const {
265265
return !(*this == other);
266266
}
267267

include/swift/SILOptimizer/Analysis/Reachability.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ class IterativeBackwardReachability final {
183183
}
184184

185185
explicit operator bool() const { return !isNoEffect(); }
186-
bool operator==(const Effect &other) { return value == other.value; }
187-
bool operator!=(const Effect &other) { return value != other.value; }
186+
bool operator==(const Effect &other) const { return value == other.value; }
187+
bool operator!=(const Effect &other) const { return value != other.value; }
188188
};
189189

190190
/// How reachable a point in the function is:

lib/Frontend/CachedDiagnostics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct SerializedSourceLoc {
4646
unsigned FileID = 0;
4747
unsigned Offset = 0;
4848

49-
bool operator==(const SerializedSourceLoc &RHS) {
49+
bool operator==(const SerializedSourceLoc &RHS) const {
5050
return FileID == RHS.FileID && Offset == RHS.Offset;
5151
}
5252
};

lib/IDE/SwiftSourceDocInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ calculateContentRange(ArrayRef<Token> Tokens) {
785785
return CharSourceRange(StartLoc, Length);
786786
}
787787

788-
bool DeclaredDecl::operator==(const DeclaredDecl& Other) {
788+
bool DeclaredDecl::operator==(const DeclaredDecl& Other) const {
789789
return VD == Other.VD;
790790
}
791791

lib/SIL/IR/SILInstruction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ bool SILInstructionResultArray::hasSameTypes(
16061606
}
16071607

16081608
bool SILInstructionResultArray::
1609-
operator==(const SILInstructionResultArray &other) {
1609+
operator==(const SILInstructionResultArray &other) const {
16101610
if (size() != other.size())
16111611
return false;
16121612
for (auto i : indices(*this))

lib/SILOptimizer/Analysis/LoopRegionAnalysis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ struct alledge_iterator {
10291029
return copy;
10301030
}
10311031

1032-
bool operator==(alledge_iterator rhs) {
1032+
bool operator==(alledge_iterator rhs) const {
10331033
if (Wrapper->Region != rhs.Wrapper->Region)
10341034
return false;
10351035
if (SubregionIter != rhs.SubregionIter)
@@ -1041,7 +1041,7 @@ struct alledge_iterator {
10411041
return BackedgeIter == rhs.BackedgeIter;
10421042
}
10431043

1044-
bool operator!=(alledge_iterator rhs) { return !(*this == rhs); }
1044+
bool operator!=(alledge_iterator rhs) const { return !(*this == rhs); }
10451045
};
10461046

10471047
} // end anonymous namespace

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1137,11 +1137,11 @@ struct TrampolineDest {
11371137
TrampolineDest(TrampolineDest &&) = default;
11381138
TrampolineDest &operator=(TrampolineDest &&) = default;
11391139

1140-
bool operator==(const TrampolineDest &rhs) {
1140+
bool operator==(const TrampolineDest &rhs) const {
11411141
return destBB == rhs.destBB
11421142
&& newSourceBranchArgs == rhs.newSourceBranchArgs;
11431143
}
1144-
bool operator!=(const TrampolineDest &rhs) {
1144+
bool operator!=(const TrampolineDest &rhs) const {
11451145
return !(*this == rhs);
11461146
}
11471147

stdlib/public/runtime/Metadata.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4845,7 +4845,7 @@ class ExtendedExistentialTypeCacheEntry {
48454845
key.Arguments.hash());
48464846
}
48474847

4848-
bool operator==(const Key &other) {
4848+
bool operator==(const Key &other) const {
48494849
return Shape == other.Shape && Arguments == other.Arguments;
48504850
}
48514851
};

0 commit comments

Comments
 (0)