mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:51:04 +01:00
Change the IdBase operator== to fix reversed operator warnings (#4636)
I believe our flags enable the warning by default, it's just that it
doesn't catch this in clang-16 (maybe more; I reproduced with clang-18
and didn't keep digging). For example:
```
toolchain/parse/tree_test.cpp:86:28: error: ISO C++20 considers use of overloaded operator '==' (with operand types 'value_type' (aka 'Carbon::Parse::NodeIdInCategory<Carbon::Parse::NodeCategory::Decl>') and 'AnyDeclId' (aka 'NodeIdInCategory<NodeCategory::Decl>')) to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]
86 | EXPECT_TRUE(*any_decl_id == any_decl_id2);
| ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~
```
The different `operator==` approach works except for with
`Parse::NodeId::Invalid`, which seems easy to replace with a
`.is_valid()` check.
This commit is contained in:
@@ -71,7 +71,7 @@ static auto HandleModifier(Context& context, Parse::NodeId node_id,
|
||||
for (auto later_order = static_cast<int8_t>(order) + 1;
|
||||
later_order <= static_cast<int8_t>(ModifierOrder::Last);
|
||||
++later_order) {
|
||||
if (s.ordered_modifier_node_ids[later_order] != Parse::NodeId::Invalid) {
|
||||
if (s.ordered_modifier_node_ids[later_order].is_valid()) {
|
||||
closest_later_modifier = s.ordered_modifier_node_ids[later_order];
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user