Skip to content

Commit be5bbd3

Browse files
committed
Re-add IsIteratorType
1 parent 6984395 commit be5bbd3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

cpp2rust/converter/converter.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
550550
auto *ctor = expr->getConstructor();
551551
if (!ctor->isCopyOrMoveConstructor() &&
552552
ctor->isConvertingConstructor(/*AllowExplicit=*/false) &&
553-
ctor->getNumParams() == 1) {
553+
ctor->getNumParams() == 1 && IsIteratorType(expr->getType())) {
554554
c.suppress_iterator_clone_ = true;
555555
}
556556
}
@@ -562,6 +562,19 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
562562
static bool take(Converter &c) {
563563
return std::exchange(c.suppress_iterator_clone_, false);
564564
}
565+
566+
private:
567+
static bool IsIteratorType(clang::QualType qt) {
568+
if (auto *record = qt->getAsCXXRecordDecl()) {
569+
for (auto *d : record->decls()) {
570+
if (auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(d)) {
571+
if (tnd->getName() == "iterator_category")
572+
return true;
573+
}
574+
}
575+
}
576+
return false;
577+
}
565578
};
566579

567580
struct PushConstInitializer {

0 commit comments

Comments
 (0)