Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable relational operators for classes and exceptions C++ #2862

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

bernardnormier
Copy link
Member

This PR disables the relational operators for classes and exceptions in C++.

Prior to this PR, they were enabled and implemented using ice_tuple, we could lead to unexpected results, in particular two classes with different types could compare equal (since the comparison slices to the common base type).

* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares less than the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value, bool> = true>
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classes and exceptions are polymorphic, while structs aren't.

@@ -105,24 +105,24 @@ allTests(Test::TestHelper* helper)
Test::CPtr c1 = make_shared<Test::C>(s1);
{
auto result = i->opCAsync(c1).get();
test(Ice::targetEqualTo(std::get<0>(result), c1));
test(Ice::targetEqualTo(std::get<1>(result), c1));
test(std::get<0>(result)->ice_tuple() == c1->ice_tuple());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need/want these comparisons, you can compare the tuples. Or you can write your own relational operators that compare the tuples (+ ice_id() and more, it's up to you).

@bernardnormier bernardnormier merged commit dfbdfb3 into zeroc-ice:main Oct 7, 2024
16 of 17 checks passed
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants