@@ -4492,18 +4492,34 @@ std::string Converter::GetComparisonCall(const clang::FunctionDecl *op,
44924492 const clang::CXXRecordDecl *decl,
44934493 std::string_view lhs,
44944494 std::string_view rhs) {
4495- auto record = GetRecordName (decl);
4496- auto arg = std::format (" {} as *const {}" , rhs, record);
4495+ auto arg = [&](unsigned i, std::string_view value) {
4496+ if (op->getParamDecl (i)->getType ()->isReferenceType ()) {
4497+ return GetComparisonReferenceArg (decl, value);
4498+ }
4499+ return std::format (" {}.clone()" , value);
4500+ };
44974501 if (const auto *method = clang::dyn_cast<clang::CXXMethodDecl>(op)) {
4498- auto recv = !MethodNeedsMutableReceiver (method)
4499- ? std::string (lhs)
4500- : std::format (" &mut *(&raw const *{}).cast_mut()" , lhs);
45014502 return std::format (" {}::{}({}, {})" , GetUFCSName (method),
4502- GetMethodName (method), recv, arg);
4503+ GetMethodName (method),
4504+ GetComparisonReceiver (method, decl, lhs), arg (0 , rhs));
4505+ }
4506+ return std::format (" {}({}, {})" , GetNamedDeclAsString (op->getCanonicalDecl ()),
4507+ arg (0 , lhs), arg (1 , rhs));
4508+ }
4509+
4510+ std::string
4511+ Converter::GetComparisonReferenceArg (const clang::CXXRecordDecl *decl,
4512+ std::string_view value) {
4513+ return std::format (" {} as *const {}" , value, GetRecordName (decl));
4514+ }
4515+
4516+ std::string Converter::GetComparisonReceiver (const clang::CXXMethodDecl *method,
4517+ const clang::CXXRecordDecl *,
4518+ std::string_view lhs) {
4519+ if (!MethodNeedsMutableReceiver (method)) {
4520+ return std::string (lhs);
45034521 }
4504- return std::format (" {}({} as *const {}, {})" ,
4505- GetNamedDeclAsString (op->getCanonicalDecl ()), lhs, record,
4506- arg);
4522+ return std::format (" &mut *(&raw const *{}).cast_mut()" , lhs);
45074523}
45084524
45094525void Converter::ConvertOrdAndPartialOrdTraits (const clang::CXXRecordDecl *decl,
0 commit comments