[PATCH] D116904: Fix build failure with MSVC in C++20 mode

Evgeny Mandrikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 9 16:12:57 PST 2022


Godin created this revision.
Godin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Without this patch when using CMAKE_CXX_STANDARD=20
and MSVC 19.30.30705.0 compilation fails with

clang\lib\Tooling\Syntax\Tree.cpp(347): error C2666: 'clang::syntax::Tree::ChildIteratorBase<clang::syntax::Tree::ChildIterator,clang::syntax::Node>::operator ==': 4 overloads have similar conversions
clang\lib\Tooling\Syntax\Tree.cpp(392): error C2666: 'clang::syntax::Tree::ChildIteratorBase<clang::syntax::Tree::ChildIterator,clang::syntax::Node>::operator ==': 4 overloads have similar conversions

Note that removed comment that
"iterator_facade_base requires == to be a member"
was made obsolete by change https://reviews.llvm.org/D78938


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116904

Files:
  clang/include/clang/Tooling/Syntax/Tree.h


Index: clang/include/clang/Tooling/Syntax/Tree.h
===================================================================
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -181,7 +181,10 @@
     ChildIteratorBase() = default;
     explicit ChildIteratorBase(NodeT *N) : N(N) {}
 
-    bool operator==(const DerivedT &O) const { return O.N == N; }
+    friend bool operator==(const DerivedT &LHS, const DerivedT &RHS) {
+      return LHS.N == RHS.N;
+    }
+
     NodeT &operator*() const { return *N; }
     DerivedT &operator++() {
       N = N->getNextSibling();
@@ -269,14 +272,6 @@
   Node *LastChild = nullptr;
 };
 
-// Provide missing non_const == const overload.
-// iterator_facade_base requires == to be a member, but implicit conversions
-// don't work on the LHS of a member operator.
-inline bool operator==(const Tree::ConstChildIterator &A,
-                       const Tree::ConstChildIterator &B) {
-  return A.operator==(B);
-}
-
 /// A list of Elements separated or terminated by a fixed token.
 ///
 /// This type models the following grammar construct:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116904.398469.patch
Type: text/x-patch
Size: 1115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220110/0e7bb8e1/attachment.bin>


More information about the cfe-commits mailing list