Closed Shachlan closed 4 years ago
Thanks for bringing it up! This should now be fixed with https://github.com/joboccara/NamedType/commit/bcc405100e185462f7221824229a0e060107da6c
Tbh I don't understand the rationale of the warning, and I see that other libraries such as Boost have had it too. In their thread they mention this could be a defect in clang. In the meantime we can work around the issue by defining the operator== as a friend rather than a member function.
@joboccara, I can't seem to be able to reopen this issue. This seems to be solved in MacOS, but I still get the warning in linux, using clang 10:
test.cpp:8:13: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'fluent::NamedType<int, FooTag, fluent::FunctionCallable, fluent::Arithmetic>' and 'fluent::NamedType<int, FooTag, fluent::FunctionCallable, fluent::Arithmetic>') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
return (a == b) ? 0 : 1;
~ ^ ~
./third_party/NamedType/include/NamedType/underlying_functionalities.hpp:286:44: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
FLUENT_NODISCARD friend constexpr bool operator==(Comparable<T> const& self, T const& other)
i have the same issue with clang-12 on linux, the following code triggers the warning:
#include <NamedType/named_type.hpp>
using Foo = fluent::NamedType<std::size_t, struct FooTag, fluent::Arithmetic>;
int main()
{
Foo{1} == Foo{2};
}
The warning is:
warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'Foo' (aka 'NamedType<unsigned long, FooTag, fluent::Arithmetic>') and 'Foo') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
Foo{1} == Foo{2};
~~~~~~ ^ ~~~~~~
namedtype/include/NamedType/underlying_functionalities.hpp:286:44: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
FLUENT_NODISCARD friend constexpr bool operator==(Comparable<T> const& self, T const& other)
^
src/main.cpp:20:12: warning: equality comparison result unused [-Wunused-comparison]
I am using the current commit of the master branch.
Compile using clang 10, get this warning: