ut icon indicating copy to clipboard operation
ut copied to clipboard

Ambiguous operator== candidate found for parameterized test using std::tuple{true, 42}; on GCC

Open theo-dep opened this issue 5 months ago • 2 comments

With the small parameterized example (https://godbolt.org/z/rbETf6PfK)

int main() {
  using namespace boost::ut;
  
  "args and types"_test =
      []<class TArg>(const TArg& arg) {
        expect(std::is_integral_v<TArg> >> fatal);
         expect(42_i == arg or "is true"_b == arg);
         expect(type<TArg> == type<int> or type<TArg> == type<bool>);
      }
    | std::tuple{true, 42};
}

I got

/app/raw.githubusercontent.com/boost-experimental/ut/master/include/boost/ut.hpp:1015:29: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
 1015 |             return get(lhs) == get(rhs);
      |                    ~~~~~~~~~^~~~~~~~~~~
/app/raw.githubusercontent.com/boost-experimental/ut/master/include/boost/ut.hpp:2607:34: note: candidate 1: 'constexpr auto boost::ext::ut::v2_3_1::literals::operator""_b(const char*, long unsigned int)::named::operator==(bool) const'
 2607 |     [[nodiscard]] constexpr auto operator==(const bool other) const {
      |                                  ^~~~~~~~
/app/raw.githubusercontent.com/boost-experimental/ut/master/include/boost/ut.hpp:1015:29: note: candidate 2: 'operator==(int, int)' (built-in)
 1015 |             return get(lhs) == get(rhs);
      |                    ~~~~~~~~~^~~~~~~~~~~

But if I static_cast the _b literal type into bool (bool("is true"_b) == arg, the warning is removed.

Is it a problem of definition, or visibility?

theo-dep avatar Aug 21 '25 08:08 theo-dep

I spot the parameterized.cpp example :D

"args and types"_test = []<class TArg>(TArg arg) {
    expect((std::is_integral_v<TArg>) >> fatal);
    expect(42_i == static_cast<int>(arg) or arg);
    expect(type<TArg> == type<int> or type<TArg> == type<bool>);
} | std::tuple{42, true};

theo-dep avatar Aug 21 '25 08:08 theo-dep

btw, readme examples are not update to date (fail to compile with cfg<override>). Examples in example folder are better :)!

theo-dep avatar Aug 21 '25 08:08 theo-dep