Skip to content

Commit 7660a7e

Browse files
author
Olivier Goffart
committed
Fix compare function return type from bool to int
The generated C++ compare function was declared as returning bool, but it calls compare_helper which returns int (-1, 0, or 1). The bool return type truncates the result, turning both -1 and 1 into 1 (true). The Rust side expects i32 and uses the sign for ordering, so comparisons like > and < gave wrong results in release mode. Fixes the cpp_class::derive_ord test in release
1 parent 9222758 commit 7660a7e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cpp_build/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void {name}({params}{comma} void* __result) {{
286286
}
287287
if class.derives("PartialOrd") {
288288
write!(output,
289-
"{line}extern \"C\" bool __cpp_compare_{hash}(const {name} *a, const {name} *b, int cmp) {{ return rustcpp::compare_helper(*a, *b, cmp); }}\n",
289+
"{line}extern \"C\" int __cpp_compare_{hash}(const {name} *a, const {name} *b, int cmp) {{ return rustcpp::compare_helper(*a, *b, cmp); }}\n",
290290
line = class.line, hash = hash, name = class.cpp).unwrap();
291291
}
292292
}

0 commit comments

Comments
 (0)