Skip to content

Commit 2e847c7

Browse files
committed
Dedup arguments passed to template pack
1 parent f532aa4 commit 2e847c7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,16 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) {
528528
(ctor && ctor->isCopyOrMoveConstructor()))
529529
? "self"
530530
: "_";
531+
} else if (auto *pdecl = llvm::dyn_cast<clang::ParmVarDecl>(decl)) {
532+
// Expanded parameter packs share one name across the expansion
533+
if (auto *fn = llvm::dyn_cast_or_null<clang::FunctionDecl>(
534+
pdecl->getDeclContext());
535+
fn && llvm::count_if(fn->parameters(), [&](const auto *p) {
536+
return p->getName() == pdecl->getName();
537+
}) > 1) {
538+
name += '_';
539+
name += std::to_string(pdecl->getFunctionScopeIndex());
540+
}
531541
}
532542

533543
return name;

0 commit comments

Comments
 (0)