Skip to content

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

@theo-dep

Description

@theo-dep

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions