Skip to content

Commit

Permalink
Fix build failure with MSVC in C++20 mode
Browse files Browse the repository at this point in the history
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

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D116904
  • Loading branch information
Godin authored and sam-mccall committed Jan 13, 2022
1 parent 61888d9 commit 971bd6f
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions clang/include/clang/Tooling/Syntax/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ class Tree : public Node {
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();
Expand Down Expand Up @@ -269,14 +272,6 @@ class Tree : public Node {
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:
Expand Down

0 comments on commit 971bd6f

Please sign in to comment.