@@ -4753,14 +4753,19 @@ std::string Converter::GetComparisonBool(const clang::FunctionDecl *op,
47534753 if (ret->isIntegerType ()) {
47544754 return std::format (" (({}) != 0)" , call);
47554755 }
4756- const auto *record = ret->getAsCXXRecordDecl ();
4756+ bool returns_ref = ret->isReferenceType ();
4757+ const auto *record = ret.getNonReferenceType ()->getAsCXXRecordDecl ();
47574758 assert (record && " unsupported comparison operator return type" );
47584759 for (const auto *found : record->getVisibleConversionFunctions ()) {
47594760 const auto *conversion = clang::dyn_cast<clang::CXXConversionDecl>(found);
47604761 if (conversion && conversion->getConversionType ()->isBooleanType ()) {
4761- return std::format (" {{ let __cmp = &{}; {}::{}({}) }}" , call,
4762- GetUFCSName (conversion), GetMethodName (conversion),
4763- GetComparisonReceiver (conversion, record, " __cmp" ));
4762+ auto receiver =
4763+ returns_ref
4764+ ? GetComparisonReferenceReceiver (conversion, record, " __cmp" )
4765+ : GetComparisonReceiver (conversion, record, " __cmp" );
4766+ return std::format (" {{ let __cmp = {}{}; {}::{}({}) }}" ,
4767+ returns_ref ? " " : " &" , call, GetUFCSName (conversion),
4768+ GetMethodName (conversion), receiver);
47644769 }
47654770 }
47664771 assert (0 && " comparison operator result has no conversion to bool" );
@@ -4773,6 +4778,13 @@ Converter::GetComparisonReferenceArg(const clang::CXXRecordDecl *decl,
47734778 return std::format (" {} as *const {}" , value, GetRecordName (decl));
47744779}
47754780
4781+ std::string
4782+ Converter::GetComparisonReferenceReceiver (const clang::CXXMethodDecl *method,
4783+ const clang::CXXRecordDecl *decl,
4784+ std::string_view ptr) {
4785+ return GetComparisonReceiver (method, decl, std::format (" &*{}" , ptr));
4786+ }
4787+
47764788std::string Converter::GetComparisonReceiver (const clang::CXXMethodDecl *method,
47774789 const clang::CXXRecordDecl *,
47784790 std::string_view lhs) {
0 commit comments