-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
GMock doesn't support noexcept functions #2472
Comments
Hi! Does this address your issue? |
Is the |
The latest release is 1.8.1 and MOCK_METHOD was introduced after that had been published. |
From skimming the |
@thejcannon, you aren't right, code with noexcept expressions compiles. Example: struct Interface {
virtual ~Interface() = default;
virtual int foo1() const = 0;
virtual int foo2() const = 0;
};
struct Mock : Interface {
MOCK_METHOD(int, foo1, (), (const, override, noexcept(false)));
MOCK_METHOD(int, foo2, (), (const, override, noexcept(noexcept(1 + 2))));
}; |
Oh man, it's worse than expected. It compiles, but has the wrong side-effects. struct Interface {
virtual ~Interface() = default;
virtual int foo1() const noexcept(false) = 0;
};
struct Mock : Interface {
MOCK_METHOD(int, foo1, (), (const, override, noexcept(false)));
};
static_assert(
!noexcept(std::declval<Mock>().foo1())
);
static_assert(
!std::is_nothrow_invocable_v<std::remove_pointer_t<decltype(&Mock::foo1)>, Mock const*>
); Both static assertions fail, which means |
If you do Scott Meyer's little "type-displayer" trick, you'll see the mock is being declared as Probably an issue with how the macro handles This comment seems to imply the authors know about this. |
Oh my goodness! There's nothing like a lovely hidden bug, isn't it? ;) |
Hi,
What is the current plan for supporting mocking
noexcept
functions? From searching StackOverflow, I understand that it's currently not possible to mocknoexcept
functions. Is there a workaround?Thanks
The text was updated successfully, but these errors were encountered: