Skip to content

[Bug]: GCC 15 does not handle MOCK_METHOD on methods with return type std::expected #4759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
erikbs opened this issue May 6, 2025 · 0 comments

Comments

@erikbs
Copy link

erikbs commented May 6, 2025

Describe the issue

In stdlibc++ in GCC 15, stricter requirements have been imposed on std::expected’s operator== to comply with C++ standard requirements. This, unfortunately, causes compilation problems when using MOCK_METHOD on a method with return type std::expected<T, U> (except if T is void). I linked to a complete example on Compiler Explorer below.

When considering if std::expected::operator== (3) is usable, the compiler concludes that there is a circular dependency and fails on a static assertion instead of concluding that variant (3) is not usable and moving on to the next candidate. It is likely a bug in GCC/libstdc++, but it is not scheduled to be fixed until GCC 15.2.

The line of code in Google Test that triggers this is line 785 in gmock-actions.h:

  bool IsDoDefault() const { return fun_ == nullptr; }

where fun_ is a std::function<F>. If F is a function signature that returns std::expected, the mentioned std::expected::operator== variant is somehow considered by the compiler (I do not exactly why that is), and again compilation fails as soon as GCC 15 evaluates its constraints.

Even though the current definition is perfectly legal C++ and standard compliant, I propose a slight modification to the definition of IsDoDefault():

  bool IsDoDefault() const { return !fun_; }

It is functionally equivalent and equally valid C++, but also works with GCC 15.

Steps to reproduce the problem

Complete minimal example:
https://godbolt.org/z/dTY65Y4v4

What version of GoogleTest are you using?

main

What operating system and version are you using?

RockyLinux 9.5

What compiler and version are you using?

GCC 15.1.0

What build system are you using?

CMake 3.31

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant