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

Crash on mingw clang for virtual destructor #210

Open
dariusarnold opened this issue May 26, 2020 · 0 comments
Open

Crash on mingw clang for virtual destructor #210

dariusarnold opened this issue May 26, 2020 · 0 comments

Comments

@dariusarnold
Copy link

Hello,
I have a problem using virtual destructors in classes that I want to mock. The code compiles with clang++ and g++ from mingw on Windows, but it only runs when compiled with g++. The executable created by clang will crash. If I make the destructor non virtual, it will run when compiled with clang++ as well. I compiled without optimizations (-O0) on both compilers.
Minimal code example:

#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <fakeit.hpp>

class Interface {
public:
	virtual ~Interface() = 0;
	virtual int f() = 0;
};


Interface::~Interface() {}


TEST_CASE("Test", "[tag]") {
    using namespace fakeit;
    Mock<Interface> mock;
    When(Method(mock, f)).AlwaysReturn(42);
    REQUIRE(mock.get().f() == 42);
}

G++ and clang++ versions:

$ g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0

$ clang++ --version
clang version 10.0.0 (https://github.com/msys2/MINGW-packages.git 3f880aaba91a3d9cdfb222dc270274731a2119a9)
Target: i686-w64-windows-gnu
Thread model: posix

A larger example built with CMake still using mingw clang 10.0.0 gives an error message during compilation. The whole build is still successful, but the executable will crash when run.

D:/git/master/cmake/../../test/fakeit\fakeit.hpp:6142:36: note: in instantiation of template class 'fakeit::FakeObject<IGetDefaultLanguage>' requested here
        static_assert(sizeof(C) == sizeof(FakeObject<C, baseclasses...>), "This is a problem");
                                   ^
D:/git/master/cmake/../../test/fakeit\fakeit.hpp:8057:35: note: in instantiation of template class 'fakeit::DynamicProxy<IGetDefaultLanguage>' requested here
                DynamicProxy<C, baseclasses...> _proxy;
                                                ^
D:/git/master/cmake/../../test/fakeit\fakeit.hpp:8307:37: note: in instantiation of template class 'fakeit::MockImpl<IGetDefaultLanguage>' requested here
        MockImpl<C, baseclasses...> impl;
                                    ^
D:/git/master/test/src/test.cpp:14:31: note: in instantiation of template class 'fakeit::Mock<IGetDefaultLanguage>' requested here
    Mock<IGetDefaultLanguage> languageMock;

Using clang from WSL, the executable will run without crashing.

$ clang++ --version
clang version 7.0.1-8 (tags/RELEASE_701/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
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