Skip to content
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

Const mock #221

Open
ToreMartinHagen opened this issue Dec 14, 2020 · 2 comments
Open

Const mock #221

ToreMartinHagen opened this issue Dec 14, 2020 · 2 comments

Comments

@ToreMartinHagen
Copy link
Contributor

ToreMartinHagen commented Dec 14, 2020

Hi.

What is the difference between these two? And why do we have MAKE_CONST_MOCK if they are the same?
MAKE_MOCK0(foo, int(), const);
MAKE_CONST_MOCK0(foo, int());

@rollbear
Copy link
Owner

Hmmm. I have to think about this one. You may have uncovered a bug, but I'm not sure ;-)

The difference is that some support functions are not tagged as const when you write MAKE_MOCKx(name, sig, const), and maybe they should be. The reason for the maybe is that I'm not sure if things would break for noexcept.

@rollbear
Copy link
Owner

There is a difference in how MAKE_CONST_MOCKn works, and adding const as the 3rd macro parameter to MAKE_MOCKn, in that a bunch of helper functions are created that are used when placing expectations. The constness must follow to those helper functions, otherwise it would not be possible to have const/non-const overloads of mock functions. However, a prime use of the 3rd macro parameter is override, and those helper functions do not override virtual functions in any base class, so forwarding the 3rd macro parameter to those functions would cause compilation errors when override is used. If it were possible (perhaps it is?) to filter out override and final from the list of words, then they could be made to be synonymous.

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

2 participants