trompeloeil icon indicating copy to clipboard operation
trompeloeil copied to clipboard

Can't mock a method taking as parameter a type with the same name than the function

Open reddwarf69 opened this issue 5 years ago • 1 comments

I tried to mock a method with this signature: void reply(reply) and the compiler complained with:

error: invalid use of non-static member function 
    9 |     TROMPELOEIL_MAKE_MOCK1(reply, void(reply));
      |                                        ^~~~~

So it thinks that the type name is actually the method again.

For better or worse AFAIK the method signature is valid, so it would be good if trompeloeil could mock such a case.

reddwarf69 avatar Jul 19 '19 15:07 reddwarf69

Wow, this is interesting. I agree that it's desirable that it should work, but I have no idea at all about how to make it work. The macro expands to an implementation of the function, and in that function body, the name refers to the function itself and not the type.

It's reasonably easy to work around, though, by being explicit about the name of the type.

https://gcc.godbolt.org/z/jnLh5v

rollbear avatar Sep 17 '19 15:09 rollbear