jbcoe / jbcoe/cc-protocol

Member comparison operators on an interface are now a hard error

Open
#401 0 comments 0 reactions 0 assignees View on GitHub
Important
Dominant language
C++
Stars
11
Forks
4
Avg merge
16h 39m
Merged PRs (30d)
131

Description

#388 lists `==`, `!=`, `<`, `<=`, `>`, `>=` and `<=>` in `is_unsupported_operator`, so `protocol_interface_function_infos` throws for any interface that declares one as a member. On `main` the same members were silently ignored, which is what DRAFT.md ("Equality and comparison operators") still describes:

```cpp
struct I { int f() const; bool operator==(const I&) const; };
struct C { int f() const { return 1; } };
protocol p(C{});
// main: compiles, operator== ignored
// #388: conformance.hh:233: uncaught exception ... 'operator== is not supported in a protocol interface'
```

The same happens for `bool operator==(const I&) const = default;` and a defaulted member `operator<=>`; `is_special_member_function` does not cover defaulted comparisons. Hidden-friend comparisons are unaffected.

Options:

1. Skip comparisons the way `main` did, keeping DRAFT.md true.
2. Keep the rejection, update DRAFT.md, and add rejection tests. `ConformsToTest.UnsupportedOperatorsAreRejected` covers only `operator=` and `operator co_await` today.
3. Forward them, which is the follow-up discussed on #388.

Whichever way, the `= default` idiom needs a decision of its own since it is the common way to write a comparison on a struct.

Contributor guide

Open the contributing guide

Research direction

Start with is_unsupported_operator, protocol_interface_function_infos, and conformance.hh:233, then review DRAFT.md's "Equality and comparison operators" section. Compare the existing behavior with ConformsToTest.UnsupportedOperatorsAreRejected, including defaulted comparisons. Done means the project has a decided behavior, matching rejection or forwarding tests, and documentation that reflects it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.