C++20 compile arrow get `operator==` ambiguous
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 91
Description
When compiling arrow-9.0.0 in C++20, I got:
```
In file included from ../arrow/cpp/src/arrow/ipc/dictionary.cc:32:
../arrow/cpp/src/arrow/record_batch.h:266:21: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'const Result>' and 'const Result>') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
return batch_ == other.batch_;
~~~~~~ ^ ~~~~~~~~~~~~
../arrow/cpp/src/arrow/util/compare.h:54:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
bool operator==(const T& other) const \{ return cast().Equals(other); }
^
In file included from ../arrow/cpp/src/arrow/ipc/dictionary.cc:18:
In file included from ../arrow/cpp/src/arrow/ipc/dictionary.h:27:
../arrow/cpp/src/arrow/result.h:278:20: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'const arrow::Status' and 'const arrow::Status') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
return status_ == other.status_;
~~~~~~~ ^ ~~~~~~~~~~~~~
../arrow/cpp/src/arrow/util/compare.h:54:57: note: in instantiation of member function 'arrow::Result>::Equals' requested here
bool operator==(const T& other) const \{ return cast().Equals(other); }
^
../arrow/cpp/src/arrow/record_batch.h:266:21: note: in instantiation of member function 'arrow::util::EqualityComparable>>::operator==' requested here
return batch_ == other.batch_;
^
../arrow/cpp/src/arrow/util/compare.h:54:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
bool operator==(const T& other) const \{ return cast().Equals(other); }
^
2 warnings generated.
In file included from ../arrow/cpp/src/arrow/ipc/message.cc:33:
In file included from ../arrow/cpp/src/arrow/ipc/reader.h:32:
../arrow/cpp/src/arrow/record_batch.h:266:21: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'const Result>' and 'const Result>') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
return batch_ == other.batch_;
~~~~~~ ^ ~~~~~~~~~~~~
../arrow/cpp/src/arrow/util/compare.h:54:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
bool operator==(const T& other) const \{ return cast().Equals(other); }
^
In file included from ../arrow/cpp/src/arrow/ipc/message.cc:18:
In file included from ../arrow/cpp/src/arrow/ipc/message.h:30:
../arrow/cpp/src/arrow/result.h:278:20: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'const arrow::Status' and 'const arrow::Status') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
return status_ == other.status_;
~~~~~~~ ^ ~~~~~~~~~~~~~
../arrow/cpp/src/arrow/util/compare.h:54:57: note: in instantiation of member function 'arrow::Result>::Equals' requested here
bool operator==(const T& other) const \{ return cast().Equals(other); }
^
../arrow/cpp/src/arrow/record_batch.h:266:21: note: in instantiation of member function 'arrow::util::EqualityComparable>>::operator==' requested here
return batch_ == other.batch_;
^
../arrow/cpp/src/arrow/util/compare.h:54:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
bool operator==(const T& other) const \{ return cast().Equals(other); }
```
Generate or hand written `operator==` for `Result` maybe fixing this problem. Seems problems cames from:
https://stackoverflow.com/questions/65833022/inherited-synthesized-comparison-operator-produces-warning-error-iso-c20-cons
**Reporter**: [Xuwei Fu](https://issues.apache.org/jira/browse/ARROW-17408) / @mapleFU
#### PRs and other links:
- [GitHub Pull Request #13874](https://github.com/apache/arrow/pull/13874)
**Note**: *This issue was originally created as [ARROW-17408](https://issues.apache.org/jira/browse/ARROW-17408). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start by reviewing cpp/src/arrow/util/compare.h, cpp/src/arrow/result.h, and cpp/src/arrow/record_batch.h, then reproduce the warning with a C++20 build. Compare the behavior with pull request #13874; done means the affected C++20 compilation no longer emits the ambiguous operator warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100