Skip to content

Commit fe2f472

Browse files
Copilotlucic71
authored andcommitted
Fix Ord codegen to use other < self in reverse branch (#170)
The generated `Ord::cmp` for method-based `operator<` used `other.<op>(other)` in its second branch, which can never evaluate true and therefore suppresses `Ordering::Greater`. This change aligns that branch with the intended reverse comparison (`other.<op>(self)`), matching existing model-specific behavior. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent a194df9 commit fe2f472

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,7 @@ void Converter::ConvertOrdAndPartialOrdTraits(const clang::CXXRecordDecl *decl,
37223722
case clang::OO_Less:
37233723
if (clang::isa<clang::CXXMethodDecl>(op)) {
37243724
first_branch = std::format("self.{}(other)", GetOverloadedOperator(op));
3725-
second_branch = std::format("other.{}(other)", GetOverloadedOperator(op));
3725+
second_branch = std::format("other.{}(self)", GetOverloadedOperator(op));
37263726
} else {
37273727
first_branch = std::format("{}(self, other)", GetOverloadedOperator(op));
37283728
second_branch = std::format("{}(other, self)", GetOverloadedOperator(op));

0 commit comments

Comments
 (0)