Skip to content

Commit aecc10e

Browse files
authored
Merge pull request #67775 from apple/egorzhdan/clang-stmt-iterator
[cxx-interop] Fix SwiftCompilerSources hosttools build
2 parents f3774ed + c621d13 commit aecc10e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,18 @@ static bool synthesizeCXXOperator(ClangImporter::Implementation &impl,
360360

361361
// Lookup the `operator==` function that will be called under the hood.
362362
clang::UnresolvedSet<16> operators;
363+
clang::sema::DelayedDiagnosticPool diagPool{
364+
impl.getClangSema().DelayedDiagnostics.getCurrentPool()};
365+
auto diagState = impl.getClangSema().DelayedDiagnostics.push(diagPool);
363366
// Note: calling `CreateOverloadedBinOp` emits an error if the looked up
364367
// function is unavailable for the current target.
365368
auto underlyingCallResult = clangSema.CreateOverloadedBinOp(
366369
clang::SourceLocation(), operatorKind, operators, lhsParamRefExpr,
367370
rhsParamRefExpr);
371+
impl.getClangSema().DelayedDiagnostics.popWithoutEmitting(diagState);
372+
373+
if (!diagPool.empty())
374+
return false;
368375
if (!underlyingCallResult.isUsable())
369376
return false;
370377
auto underlyingCall = underlyingCallResult.get();

test/Interop/Cxx/stdlib/overlay/Inputs/custom-iterator.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,4 +958,55 @@ struct MutableRACIterator {
958958
}
959959
};
960960

961+
/// clang::StmtIteratorBase
962+
class ProtectedIteratorBase {
963+
protected:
964+
int value;
965+
ProtectedIteratorBase() : value(0) {}
966+
};
967+
968+
/// clang::StmtIteratorImpl
969+
template <typename DERIVED>
970+
class ProtectedIteratorImpl : public ProtectedIteratorBase {
971+
protected:
972+
ProtectedIteratorImpl(const ProtectedIteratorBase& RHS) : ProtectedIteratorBase(RHS) {}
973+
974+
public:
975+
using iterator_category = std::forward_iterator_tag;
976+
using value_type = int;
977+
using difference_type = std::ptrdiff_t;
978+
using pointer = int *;
979+
using reference = int &;
980+
981+
ProtectedIteratorImpl() = default;
982+
983+
DERIVED& operator++() {
984+
value++;
985+
return static_cast<DERIVED&>(*this);
986+
}
987+
988+
DERIVED operator++(int) {
989+
DERIVED tmp = static_cast<DERIVED&>(*this);
990+
operator++();
991+
return tmp;
992+
}
993+
994+
friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
995+
return LHS.value == RHS.value;
996+
}
997+
998+
reference operator*() const {
999+
return value;
1000+
}
1001+
};
1002+
1003+
/// StmtIterator
1004+
struct HasInheritedProtectedCopyConstructor : public ProtectedIteratorImpl<HasInheritedProtectedCopyConstructor> {
1005+
HasInheritedProtectedCopyConstructor() = default;
1006+
1007+
private:
1008+
HasInheritedProtectedCopyConstructor(const ProtectedIteratorBase &other)
1009+
: ProtectedIteratorImpl<HasInheritedProtectedCopyConstructor>(other) {}
1010+
};
1011+
9611012
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_CUSTOM_ITERATOR_H

0 commit comments

Comments
 (0)