Skip to content

Commit ad9c80f

Browse files
committed
Dedup conversion operators for types that have the same translation
1 parent 28b0282 commit ad9c80f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,20 @@ std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) {
10761076
return GetOverloadedFunctionName(decl);
10771077
}
10781078
if (auto *conversion = clang::dyn_cast<clang::CXXConversionDecl>(decl)) {
1079-
return GetConversionName(
1079+
auto name = GetConversionName(
10801080
conversion, GetUnsafeTypeAsString(conversion->getConversionType()));
1081+
const auto *record = conversion->getParent();
1082+
bool shared = std::any_of(
1083+
record->method_begin(), record->method_end(),
1084+
[&](const clang::CXXMethodDecl *method) {
1085+
auto *other = clang::dyn_cast<clang::CXXConversionDecl>(method);
1086+
return other && other != conversion &&
1087+
GetConversionName(other, GetUnsafeTypeAsString(
1088+
other->getConversionType())) ==
1089+
name;
1090+
});
1091+
return shared ? name + std::format("_{}", GetMethodIndex(conversion))
1092+
: name;
10811093
}
10821094
return GetNamedDeclAsString(decl);
10831095
}

0 commit comments

Comments
 (0)