diff --git a/clang/include/clang/AST/StmtIterator.h b/clang/include/clang/AST/StmtIterator.h --- a/clang/include/clang/AST/StmtIterator.h +++ b/clang/include/clang/AST/StmtIterator.h @@ -104,12 +104,13 @@ return tmp; } - bool operator==(const DERIVED& RHS) const { - return stmt == RHS.stmt && DGI == RHS.DGI && RawVAPtr == RHS.RawVAPtr; + friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) { + return LHS.stmt == RHS.stmt && LHS.DGI == RHS.DGI && + LHS.RawVAPtr == RHS.RawVAPtr; } - bool operator!=(const DERIVED& RHS) const { - return stmt != RHS.stmt || DGI != RHS.DGI || RawVAPtr != RHS.RawVAPtr; + friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) { + return !(LHS == RHS); } REFERENCE operator*() const { diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -60,6 +60,12 @@ struct OpenMPDirectiveKindExWrapper { OpenMPDirectiveKindExWrapper(unsigned Value) : Value(Value) {} OpenMPDirectiveKindExWrapper(OpenMPDirectiveKind DK) : Value(unsigned(DK)) {} + bool operator==(OpenMPDirectiveKindExWrapper V) const { + return Value == V.Value; + } + bool operator!=(OpenMPDirectiveKindExWrapper V) const { + return Value != V.Value; + } bool operator==(OpenMPDirectiveKind V) const { return Value == unsigned(V); } bool operator!=(OpenMPDirectiveKind V) const { return Value != unsigned(V); } bool operator<(OpenMPDirectiveKind V) const { return Value < unsigned(V); } diff --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp @@ -102,7 +102,10 @@ } struct FunctionData { - FunctionData() = delete; + FunctionData(const FunctionDecl *FDecl, StringRef Name, + std::string FullName) + : FDecl(FDecl), Name(Name), FullName(std::move(FullName)) {} + FunctionData(const FunctionData &) = default; FunctionData(FunctionData &&) = default; FunctionData &operator=(const FunctionData &) = delete; diff --git a/llvm/include/llvm/ADT/AllocatorList.h b/llvm/include/llvm/ADT/AllocatorList.h --- a/llvm/include/llvm/ADT/AllocatorList.h +++ b/llvm/include/llvm/ADT/AllocatorList.h @@ -118,13 +118,6 @@ reference operator*() const { return base_type::wrapped()->V; } pointer operator->() const { return &operator*(); } - - friend bool operator==(const IteratorImpl &L, const IteratorImpl &R) { - return L.wrapped() == R.wrapped(); - } - friend bool operator!=(const IteratorImpl &L, const IteratorImpl &R) { - return !(L == R); - } }; public: diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -1244,19 +1244,18 @@ return Ptr; } - bool operator==(const ConstIterator &RHS) const { - assert((!Ptr || isHandleInSync()) && "handle not in sync!"); + friend bool operator==(const DenseMapIterator &LHS, + const DenseMapIterator &RHS) { + assert((!LHS.Ptr || LHS.isHandleInSync()) && "handle not in sync!"); assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!"); - assert(getEpochAddress() == RHS.getEpochAddress() && + assert(LHS.getEpochAddress() == RHS.getEpochAddress() && "comparing incomparable iterators!"); - return Ptr == RHS.Ptr; + return LHS.Ptr == RHS.Ptr; } - bool operator!=(const ConstIterator &RHS) const { - assert((!Ptr || isHandleInSync()) && "handle not in sync!"); - assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!"); - assert(getEpochAddress() == RHS.getEpochAddress() && - "comparing incomparable iterators!"); - return Ptr != RHS.Ptr; + + friend bool operator!=(const DenseMapIterator &LHS, + const DenseMapIterator &RHS) { + return !(LHS == RHS); } inline DenseMapIterator& operator++() { // Preincrement diff --git a/llvm/include/llvm/ADT/DenseSet.h b/llvm/include/llvm/ADT/DenseSet.h --- a/llvm/include/llvm/ADT/DenseSet.h +++ b/llvm/include/llvm/ADT/DenseSet.h @@ -124,8 +124,12 @@ Iterator& operator++() { ++I; return *this; } Iterator operator++(int) { auto T = *this; ++I; return T; } - bool operator==(const ConstIterator& X) const { return I == X.I; } - bool operator!=(const ConstIterator& X) const { return I != X.I; } + friend bool operator==(const Iterator &X, const Iterator &Y) { + return X.I == Y.I; + } + friend bool operator!=(const Iterator &X, const Iterator &Y) { + return X.I != Y.I; + } }; class ConstIterator { @@ -149,8 +153,12 @@ ConstIterator& operator++() { ++I; return *this; } ConstIterator operator++(int) { auto T = *this; ++I; return T; } - bool operator==(const ConstIterator& X) const { return I == X.I; } - bool operator!=(const ConstIterator& X) const { return I != X.I; } + friend bool operator==(const ConstIterator &X, const ConstIterator &Y) { + return X.I == Y.I; + } + friend bool operator!=(const ConstIterator &X, const ConstIterator &Y) { + return X.I != Y.I; + } }; using iterator = Iterator; diff --git a/llvm/include/llvm/ADT/DirectedGraph.h b/llvm/include/llvm/ADT/DirectedGraph.h --- a/llvm/include/llvm/ADT/DirectedGraph.h +++ b/llvm/include/llvm/ADT/DirectedGraph.h @@ -38,8 +38,10 @@ /// Static polymorphism: delegate implementation (via isEqualTo) to the /// derived class. - bool operator==(const EdgeType &E) const { return getDerived().isEqualTo(E); } - bool operator!=(const EdgeType &E) const { return !operator==(E); } + bool operator==(const DGEdge &E) const { + return getDerived().isEqualTo(E.getDerived()); + } + bool operator!=(const DGEdge &E) const { return !operator==(E); } /// Retrieve the target node this edge connects to. const NodeType &getTargetNode() const { return TargetNode; } @@ -91,8 +93,12 @@ /// Static polymorphism: delegate implementation (via isEqualTo) to the /// derived class. - bool operator==(const NodeType &N) const { return getDerived().isEqualTo(N); } - bool operator!=(const NodeType &N) const { return !operator==(N); } + friend bool operator==(const NodeType &M, const NodeType &N) { + return M.isEqualTo(N); + } + friend bool operator!=(const NodeType &M, const NodeType &N) { + return !(M == N); + } const_iterator begin() const { return Edges.begin(); } const_iterator end() const { return Edges.end(); } diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -558,12 +558,12 @@ return *this; } - using BaseT::operator==; - bool operator==(const early_inc_iterator_impl &RHS) const { + friend bool operator==(const early_inc_iterator_impl &LHS, + const early_inc_iterator_impl &RHS) { #if LLVM_ENABLE_ABI_BREAKING_CHECKS - assert(!IsEarlyIncremented && "Cannot compare after dereferencing!"); + assert(!LHS.IsEarlyIncremented && "Cannot compare after dereferencing!"); #endif - return BaseT::operator==(RHS); + return (const BaseT &)LHS == (const BaseT &)RHS; } }; diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/include/llvm/ADT/StringMap.h @@ -367,7 +367,9 @@ return static_cast(*this); } - bool operator==(const DerivedTy &RHS) const { return Ptr == RHS.Ptr; } + friend bool operator==(const DerivedTy &LHS, const DerivedTy &RHS) { + return LHS.Ptr == RHS.Ptr; + } DerivedTy &operator++() { // Preincrement ++Ptr; diff --git a/llvm/include/llvm/ADT/iterator.h b/llvm/include/llvm/ADT/iterator.h --- a/llvm/include/llvm/ADT/iterator.h +++ b/llvm/include/llvm/ADT/iterator.h @@ -142,28 +142,24 @@ return tmp; } - bool operator!=(const DerivedT &RHS) const { - return !static_cast(this)->operator==(RHS); - } - bool operator>(const DerivedT &RHS) const { static_assert( IsRandomAccess, "Relational operators are only defined for random access iterators."); - return !static_cast(this)->operator<(RHS) && - !static_cast(this)->operator==(RHS); + return !(static_cast(*this) < RHS) && + !(static_cast(*this) == RHS); } bool operator<=(const DerivedT &RHS) const { static_assert( IsRandomAccess, "Relational operators are only defined for random access iterators."); - return !static_cast(this)->operator>(RHS); + return !(static_cast(*this) > RHS); } bool operator>=(const DerivedT &RHS) const { static_assert( IsRandomAccess, "Relational operators are only defined for random access iterators."); - return !static_cast(this)->operator<(RHS); + return !(static_cast(*this) < RHS); } PointerT operator->() { return &static_cast(this)->operator*(); } @@ -260,12 +256,20 @@ return *static_cast(this); } - bool operator==(const DerivedT &RHS) const { return I == RHS.I; } - bool operator<(const DerivedT &RHS) const { + friend bool operator==(const iterator_adaptor_base &LHS, + const iterator_adaptor_base &RHS) { + return LHS.I == RHS.I; + } + friend bool operator!=(const iterator_adaptor_base &LHS, + const iterator_adaptor_base &RHS) { + return !(LHS == RHS); + } + friend bool operator<(const iterator_adaptor_base &LHS, + const iterator_adaptor_base &RHS) { static_assert( BaseT::IsRandomAccess, "Relational operators are only defined for random access iterators."); - return I < RHS.I; + return LHS.I < RHS.I; } ReferenceT operator*() const { return *I; } diff --git a/llvm/include/llvm/CodeGen/LiveInterval.h b/llvm/include/llvm/CodeGen/LiveInterval.h --- a/llvm/include/llvm/CodeGen/LiveInterval.h +++ b/llvm/include/llvm/CodeGen/LiveInterval.h @@ -731,10 +731,10 @@ ++*this; return res; } - bool operator!=(const SingleLinkedListIterator &Other) { + bool operator!=(const SingleLinkedListIterator &Other) const { return P != Other.operator->(); } - bool operator==(const SingleLinkedListIterator &Other) { + bool operator==(const SingleLinkedListIterator &Other) const { return P == Other.operator->(); } T &operator*() const { diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -874,10 +874,8 @@ bool td_empty() const { return TargetDepAttrs.empty(); } - bool operator==(const AttrBuilder &B); - bool operator!=(const AttrBuilder &B) { - return !(*this == B); - } + bool operator==(const AttrBuilder &B) const; + bool operator!=(const AttrBuilder &B) const { return !(*this == B); } }; namespace AttributeFuncs { diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/llvm/include/llvm/IR/BasicBlock.h @@ -313,7 +313,9 @@ phi_iterator_impl() = default; // Allow conversion between instantiations where valid. - template + template ::value>> phi_iterator_impl(const phi_iterator_impl &Arg) : PN(Arg.PN) {} diff --git a/llvm/include/llvm/Object/StackMapParser.h b/llvm/include/llvm/Object/StackMapParser.h --- a/llvm/include/llvm/Object/StackMapParser.h +++ b/llvm/include/llvm/Object/StackMapParser.h @@ -35,11 +35,13 @@ return tmp; } - bool operator==(const AccessorIterator &Other) { + bool operator==(const AccessorIterator &Other) const { return A.P == Other.A.P; } - bool operator!=(const AccessorIterator &Other) { return !(*this == Other); } + bool operator!=(const AccessorIterator &Other) const { + return !(*this == Other); + } AccessorT& operator*() { return A; } AccessorT* operator->() { return &A; } diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h --- a/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h +++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h @@ -67,10 +67,10 @@ increment(); return *this; } - bool operator==(const CoverageMappingIterator &RHS) { + bool operator==(const CoverageMappingIterator &RHS) const { return Reader == RHS.Reader; } - bool operator!=(const CoverageMappingIterator &RHS) { + bool operator!=(const CoverageMappingIterator &RHS) const { return Reader != RHS.Reader; } Expected operator*() { diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -50,8 +50,12 @@ InstrProfIterator(InstrProfReader *Reader) : Reader(Reader) { Increment(); } InstrProfIterator &operator++() { Increment(); return *this; } - bool operator==(const InstrProfIterator &RHS) { return Reader == RHS.Reader; } - bool operator!=(const InstrProfIterator &RHS) { return Reader != RHS.Reader; } + bool operator==(const InstrProfIterator &RHS) const { + return Reader == RHS.Reader; + } + bool operator!=(const InstrProfIterator &RHS) const { + return Reader != RHS.Reader; + } value_type &operator*() { return Record; } value_type *operator->() { return &Record; } }; diff --git a/llvm/include/llvm/Support/BinaryStreamRef.h b/llvm/include/llvm/Support/BinaryStreamRef.h --- a/llvm/include/llvm/Support/BinaryStreamRef.h +++ b/llvm/include/llvm/Support/BinaryStreamRef.h @@ -121,12 +121,12 @@ bool valid() const { return BorrowedImpl != nullptr; } - bool operator==(const RefType &Other) const { - if (BorrowedImpl != Other.BorrowedImpl) + friend bool operator==(const RefType &Self, const RefType &Other) { + if (Self.BorrowedImpl != Other.BorrowedImpl) return false; - if (ViewOffset != Other.ViewOffset) + if (Self.ViewOffset != Other.ViewOffset) return false; - if (Length != Other.Length) + if (Self.Length != Other.Length) return false; return true; } diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -590,10 +590,10 @@ return It; } - bool operator==(const RepeatedSubstringIterator &Other) { + bool operator==(const RepeatedSubstringIterator &Other) const { return N == Other.N; } - bool operator!=(const RepeatedSubstringIterator &Other) { + bool operator!=(const RepeatedSubstringIterator &Other) const { return !(*this == Other); } diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp --- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp +++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp @@ -330,7 +330,7 @@ return RegSrcs[Idx].SubReg; } - bool operator==(const ValueTrackerResult &Other) { + bool operator==(const ValueTrackerResult &Other) const { if (Other.getInst() != getInst()) return false; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1729,7 +1729,7 @@ return Alignment != 0; } -bool AttrBuilder::operator==(const AttrBuilder &B) { +bool AttrBuilder::operator==(const AttrBuilder &B) const { if (Attrs != B.Attrs) return false; diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -665,7 +665,7 @@ if (auto *T = dyn_cast_or_null(Attachment.second)) for (unsigned N = 0; N < T->getNumOperands(); ++N) if (auto *Loc = dyn_cast_or_null(T->getOperand(N))) - if (Loc != DebugLoc()) + if (Loc != DebugLoc().get()) T->replaceOperandWith(N, remapDebugLoc(Loc)); } } diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -149,8 +149,8 @@ // The instruction (VN) which uses the values flowing out of CHI. Instruction *I; - bool operator==(const CHIArg &A) { return VN == A.VN; } - bool operator!=(const CHIArg &A) { return !(*this == A); } + bool operator==(const CHIArg &A) const { return VN == A.VN; } + bool operator!=(const CHIArg &A) const { return !(*this == A); } }; using CHIIt = SmallVectorImpl::iterator; diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp --- a/llvm/unittests/ADT/STLExtrasTest.cpp +++ b/llvm/unittests/ADT/STLExtrasTest.cpp @@ -463,21 +463,21 @@ // Check fancy pointer overload for unique_ptr std::unique_ptr V2 = std::make_unique(0); - EXPECT_EQ(V2.get(), to_address(V2)); + EXPECT_EQ(V2.get(), (to_address)(V2)); V2.reset(V1); - EXPECT_EQ(V1, to_address(V2)); + EXPECT_EQ(V1, (to_address)(V2)); V2.release(); // Check fancy pointer overload for shared_ptr std::shared_ptr V3 = std::make_shared(0); std::shared_ptr V4 = V3; EXPECT_EQ(V3.get(), V4.get()); - EXPECT_EQ(V3.get(), to_address(V3)); - EXPECT_EQ(V4.get(), to_address(V4)); + EXPECT_EQ(V3.get(), (to_address)(V3)); + EXPECT_EQ(V4.get(), (to_address)(V4)); V3.reset(V1); - EXPECT_EQ(V1, to_address(V3)); + EXPECT_EQ(V1, (to_address)(V3)); } TEST(STLExtrasTest, partition_point) { diff --git a/llvm/unittests/Support/DJBTest.cpp b/llvm/unittests/Support/DJBTest.cpp --- a/llvm/unittests/Support/DJBTest.cpp +++ b/llvm/unittests/Support/DJBTest.cpp @@ -24,6 +24,7 @@ {{"qqqqqqqqqqqqqqqqqqqq"}, {"QQQQQQQQQQQQQQQQQQQQ"}}, {{"I"}, {"i"}}, +#ifndef __cpp_char8_t // Latin Small Letter Dotless I {{u8"\u0130"}, {"i"}}, // Latin Capital Letter I With Dot Above @@ -47,6 +48,7 @@ {{u8"\uff2d"}, {u8"\uff4d"}}, // Old Hungarian Capital Letter Ej {{u8"\U00010c92"}, {u8"\U00010cd2"}}, +#endif }; for (const TestCase &T : Tests) { @@ -79,6 +81,7 @@ } } +#ifndef __cpp_char8_t TEST(DJBTest, knownValuesUnicode) { EXPECT_EQ(5866553u, djbHash(u8"\u0130")); EXPECT_EQ(177678u, caseFoldingDjbHash(u8"\u0130")); @@ -93,3 +96,4 @@ u8"\u0130\u0131\u00c0\u00e0\u0100\u0101\u0139\u013a\u0415\u0435\u1ea6" u8"\u1ea7\u212a\u006b\u2c1d\u2c4d\uff2d\uff4d\U00010c92\U00010cd2")); } +#endif \ No newline at end of file diff --git a/llvm/unittests/Support/JSONTest.cpp b/llvm/unittests/Support/JSONTest.cpp --- a/llvm/unittests/Support/JSONTest.cpp +++ b/llvm/unittests/Support/JSONTest.cpp @@ -173,12 +173,14 @@ Compare(R"("\"\\\b\f\n\r\t")", "\"\\\b\f\n\r\t"); Compare(R"("\u0000")", llvm::StringRef("\0", 1)); Compare("\"\x7f\"", "\x7f"); +#ifndef __cpp_char8_t Compare(R"("\ud801\udc37")", u8"\U00010437"); // UTF16 surrogate pair escape. Compare("\"\xE2\x82\xAC\xF0\x9D\x84\x9E\"", u8"\u20ac\U0001d11e"); // UTF8 Compare( R"("LoneLeading=\ud801, LoneTrailing=\udc01, LeadingLeadingTrailing=\ud801\ud801\udc37")", u8"LoneLeading=\ufffd, LoneTrailing=\ufffd, " u8"LeadingLeadingTrailing=\ufffd\U00010437"); // Invalid unicode. +#endif Compare(R"({"":0,"":0})", Object{{"", 0}}); Compare(R"({"obj":{},"arr":[]})", Object{{"obj", Object{}}, {"arr", {}}});