Skip to content

Commit

Permalink
DenseMap: fix build with clang in C++20 mode
Browse files Browse the repository at this point in the history
clang was complaing about this code:
llvm/include/llvm/IR/PassManager.h:715:17: error: ISO C++20 considers use of overloaded operator '!=' to be ambiguous despite there being a unique best viable function with non-reversed arguments [-Werror,-Wambiguous-reversed-operator]
      if (IMapI != IsResultInvalidated.end())
          ~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/include/llvm/ADT/DenseMap.h:1253:8: note: candidate function with non-reversed arguments
  bool operator!=(const ConstIterator &RHS) const {
       ^
llvm/include/llvm/ADT/DenseMap.h:1246:8: note: ambiguous candidate function with reversed arguments
  bool operator==(const ConstIterator &RHS) const {
       ^

The warning is triggered when the DenseMapIterator (lhs) is not const and so
the == operator is applied to different types on lhs/rhs.
Using a template allows the function to be available for both const/non-const
iterator types and gets rid of the warning
  • Loading branch information
nunoplopes committed Dec 8, 2020
1 parent 78976bf commit 3c01af9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions llvm/include/llvm/ADT/DenseMap.h
Expand Up @@ -1189,8 +1189,6 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, false>;

using ConstIterator = DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;

public:
using difference_type = ptrdiff_t;
using value_type =
Expand Down Expand Up @@ -1243,14 +1241,17 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
return Ptr;
}

bool operator==(const ConstIterator &RHS) const {
template <typename T>
bool operator==(const T &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;
}
bool operator!=(const ConstIterator &RHS) const {

template <typename T>
bool operator!=(const T &RHS) const {
assert((!Ptr || isHandleInSync()) && "handle not in sync!");
assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!");
assert(getEpochAddress() == RHS.getEpochAddress() &&
Expand Down

0 comments on commit 3c01af9

Please sign in to comment.