[llvm] 3c01af9 - DenseMap: fix build with clang in C++20 mode

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 17:52:14 PST 2020


Using an unconstrained template doesn't seem like the most elegant solution
here.

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)

On Tue, Dec 8, 2020 at 10:39 AM Nuno Lopes via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Nuno Lopes
> Date: 2020-12-08T18:39:31Z
> New Revision: 3c01af9aeebe01030e6138cece02675d2f148bb3
>
> URL:
> https://github.com/llvm/llvm-project/commit/3c01af9aeebe01030e6138cece02675d2f148bb3
> DIFF:
> https://github.com/llvm/llvm-project/commit/3c01af9aeebe01030e6138cece02675d2f148bb3.diff
>
> LOG: DenseMap: fix build with clang in C++20 mode
> 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
>
> Added:
>
>
> Modified:
>     llvm/include/llvm/ADT/DenseMap.h
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/include/llvm/ADT/DenseMap.h
> b/llvm/include/llvm/ADT/DenseMap.h
> index f591ee07ac00..7da347125c34 100644
> --- a/llvm/include/llvm/ADT/DenseMap.h
> +++ b/llvm/include/llvm/ADT/DenseMap.h
> @@ -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
> diff erence_type = ptr
> diff _t;
>    using value_type =
> @@ -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() &&
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201214/988d07be/attachment.html>


More information about the llvm-commits mailing list