<div dir="ltr">Using an unconstrained template doesn't seem like the most elegant solution here.<br><br>Would this issue be addressed by making these non-member functions, so the LHS and RHS are treated more similarly? (they can still be written inline as friends, so it shouldn't change the syntax terribly much)</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 8, 2020 at 10:39 AM Nuno Lopes via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Nuno Lopes<br>
Date: 2020-12-08T18:39:31Z<br>
New Revision: 3c01af9aeebe01030e6138cece02675d2f148bb3<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/3c01af9aeebe01030e6138cece02675d2f148bb3" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/3c01af9aeebe01030e6138cece02675d2f148bb3</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/3c01af9aeebe01030e6138cece02675d2f148bb3.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/3c01af9aeebe01030e6138cece02675d2f148bb3.diff</a><br>
<br>
LOG: DenseMap: fix build with clang in C++20 mode<br>
clang was complaing about this code:<br>
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]<br>
if (IMapI != IsResultInvalidated.end())<br>
~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~<br>
llvm/include/llvm/ADT/DenseMap.h:1253:8: note: candidate function with non-reversed arguments<br>
bool operator!=(const ConstIterator &RHS) const {<br>
^<br>
llvm/include/llvm/ADT/DenseMap.h:1246:8: note: ambiguous candidate function with reversed arguments<br>
bool operator==(const ConstIterator &RHS) const {<br>
^<br>
<br>
The warning is triggered when the DenseMapIterator (lhs) is not const and so<br>
the == operator is applied to different types on lhs/rhs.<br>
Using a template allows the function to be available for both const/non-const<br>
iterator types and gets rid of the warning<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
llvm/include/llvm/ADT/DenseMap.h<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h<br>
index f591ee07ac00..7da347125c34 100644<br>
--- a/llvm/include/llvm/ADT/DenseMap.h<br>
+++ b/llvm/include/llvm/ADT/DenseMap.h<br>
@@ -1189,8 +1189,6 @@ class DenseMapIterator : DebugEpochBase::HandleBase {<br>
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;<br>
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, false>;<br>
<br>
- using ConstIterator = DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;<br>
-<br>
public:<br>
using <br>
diff erence_type = ptr<br>
diff _t;<br>
using value_type =<br>
@@ -1243,14 +1241,17 @@ class DenseMapIterator : DebugEpochBase::HandleBase {<br>
return Ptr;<br>
}<br>
<br>
- bool operator==(const ConstIterator &RHS) const {<br>
+ template <typename T><br>
+ bool operator==(const T &RHS) const {<br>
assert((!Ptr || isHandleInSync()) && "handle not in sync!");<br>
assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!");<br>
assert(getEpochAddress() == RHS.getEpochAddress() &&<br>
"comparing incomparable iterators!");<br>
return Ptr == RHS.Ptr;<br>
}<br>
- bool operator!=(const ConstIterator &RHS) const {<br>
+<br>
+ template <typename T><br>
+ bool operator!=(const T &RHS) const {<br>
assert((!Ptr || isHandleInSync()) && "handle not in sync!");<br>
assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!");<br>
assert(getEpochAddress() == RHS.getEpochAddress() &&<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>