Skip to content

[cxx-interop] Fix SwiftCompilerSources hosttools build #67775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/ClangImporter/ClangDerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,18 @@ static bool synthesizeCXXOperator(ClangImporter::Implementation &impl,

// Lookup the `operator==` function that will be called under the hood.
clang::UnresolvedSet<16> operators;
clang::sema::DelayedDiagnosticPool diagPool{
impl.getClangSema().DelayedDiagnostics.getCurrentPool()};
auto diagState = impl.getClangSema().DelayedDiagnostics.push(diagPool);
// Note: calling `CreateOverloadedBinOp` emits an error if the looked up
// function is unavailable for the current target.
auto underlyingCallResult = clangSema.CreateOverloadedBinOp(
clang::SourceLocation(), operatorKind, operators, lhsParamRefExpr,
rhsParamRefExpr);
impl.getClangSema().DelayedDiagnostics.popWithoutEmitting(diagState);

if (!diagPool.empty())
return false;
if (!underlyingCallResult.isUsable())
return false;
auto underlyingCall = underlyingCallResult.get();
Expand Down
51 changes: 51 additions & 0 deletions test/Interop/Cxx/stdlib/overlay/Inputs/custom-iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,55 @@ struct MutableRACIterator {
}
};

/// clang::StmtIteratorBase
class ProtectedIteratorBase {
protected:
int value;
ProtectedIteratorBase() : value(0) {}
};

/// clang::StmtIteratorImpl
template <typename DERIVED>
class ProtectedIteratorImpl : public ProtectedIteratorBase {
protected:
ProtectedIteratorImpl(const ProtectedIteratorBase& RHS) : ProtectedIteratorBase(RHS) {}

public:
using iterator_category = std::forward_iterator_tag;
using value_type = int;
using difference_type = std::ptrdiff_t;
using pointer = int *;
using reference = int &;

ProtectedIteratorImpl() = default;

DERIVED& operator++() {
value++;
return static_cast<DERIVED&>(*this);
}

DERIVED operator++(int) {
DERIVED tmp = static_cast<DERIVED&>(*this);
operator++();
return tmp;
}

friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
return LHS.value == RHS.value;
}

reference operator*() const {
return value;
}
};

/// StmtIterator
struct HasInheritedProtectedCopyConstructor : public ProtectedIteratorImpl<HasInheritedProtectedCopyConstructor> {
HasInheritedProtectedCopyConstructor() = default;

private:
HasInheritedProtectedCopyConstructor(const ProtectedIteratorBase &other)
: ProtectedIteratorImpl<HasInheritedProtectedCopyConstructor>(other) {}
};

#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_CUSTOM_ITERATOR_H