eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.22k stars 170 forks source link

Fix MOCK_TYPE macro adding a typename #267

Closed morbo84 closed 2 years ago

morbo84 commented 2 years ago

Under some scenarios, the typename keyword might be required.

FranckRJ commented 2 years ago

Do you have any example where it is required?

morbo84 commented 2 years ago

Sorry, false alarm!

morbo84 commented 2 years ago

@FranckRJ OK, let's start anew. 🙂

I'm hitting this compilation error with a specific compiler version (clang 8.0.1); in a first moment, I thought I was able to get rid of it without requiring changes to you, but that was not the case.

You can see that, adding the typename keyword where I added in the PR, the compilation error is fixed.

coveralls commented 2 years ago

Coverage Status

Coverage remained the same at 99.926% when pulling 21ea210ce85ee60df0abfbd8822304366f536ff2 on morbo84:master into 38c118c2be2fe33148545b1c32dc568eeabe1f23 on eranpeer:master.

morbo84 commented 2 years ago

I can add some details. The example is as simple as that:

struct Struct {};

struct Interface {
    virtual Struct* foo() = 0;
    virtual const Struct* foo() const = 0;
};

template<typename MyType>
void doStuff() {
    auto actorMovementProxy = std::make_shared<fakeit::Mock<MyType>>();
    fakeit::When(OverloadedMethod((*actorMovementProxy), foo, Struct * ())).AlwaysReturn(nullptr);
}

void boh() {
    doStuff<Interface>();
}

Here you can find a live example of the failure; I've pasted the fakeit standalone header on top of my example and you can see that every version of clang (from 8.0.1 to current) and also GCC are failing to compile it, whereas MSVC doesn't complain (as usual). Adding the typename keyword before MOCK_TYPE's usages fixes the issue.

FranckRJ commented 2 years ago

I'll look into it this weekend.