apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.48k stars 3.52k forks source link

C++20 compile arrow get `operator==` ambiguous #32677

Open asfimport opened 2 years ago

asfimport commented 2 years ago

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<std::shared_ptr<RecordBatch>>' and 'const Result<std::shared_ptr<RecordBatch>>') 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<std::shared_ptr<arrow::RecordBatch>>::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<arrow::Result<std::shared_ptr<arrow::RecordBatch>>>::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<std::shared_ptr<RecordBatch>>' and 'const Result<std::shared_ptr<RecordBatch>>') 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<std::shared_ptr<arrow::RecordBatch>>::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<arrow::Result<std::shared_ptr<arrow::RecordBatch>>>::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 / @mapleFU

PRs and other links:

Note: This issue was originally created as ARROW-17408. Please see the migration documentation for further details.

asfimport commented 2 years ago

Xuwei Fu / @mapleFU: @pitrou Hi, mind take a look? My fixing works for C+20, but would not compile in some platforms. Should I add some macros that make it only works in C+20?