The newest update of Microsoft Visual Studio 2019 (16.4) is causing all googlemock mock methods to fail with an SEH Exception 0xc0000005 thrown. The mock methods are throwing this exception at mock object destruction this leads to leaked mock objects, and consequently failed tests. This test was built from the release-1.10.0 tag of this git repository. Mock methods are working correctly with compiled with GCC on Ubuntu Linux.
The minimum code to reproduce is listed below. This example was build with Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28314 for x86. CMake was used to generate the build files. gmock_main was used as the program's entry point.
#pragma once
class TestClass {
public:
virtual void TestMethod() = 0;
virtual ~TestClass() = default;
};
#pragma once
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "TestClass.h"
class MockTest final : public TestClass {
public:
MOCK_METHOD(void, TestMethod, (), (override));
};
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "MockTest.h"
using namespace testing;
TEST(Test, t) {
MockTest t;
EXPECT_CALL(t, TestMethod()).Times(1);
t.TestMethod();
}
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Test
[ RUN ] Test.t
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[ FAILED ] Test.t (1 ms)
[----------] 1 test from Test (2 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (5 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Test.t
1 FAILED TEST
..\..\..\test\Test.cpp(11): ERROR: this mock object (used in test Test.t) should be deleted but never is. Its address is @000000FB9D96F490.
ERROR: 1 leaked mock object found at program exit. Expectations on a mock object is verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock.
After some more exploring it appears that compiling with c++17 enabled caused this issue. The setting set(CMAKE_CXX_STANDARD 17) in the CMakeLists.txt was causing mocked tests to fail with the SEH exception code 0xc0000005 on Microsoft's compiler. Compiling with set(CMAKE_CXX_STANDARD 11) and set(CMAKE_CXX_STANDARD 14) seems to work as expected.
The current project I am working on has had c++17 enabled since its beginning with mocked classes working until the Visual Studio 2019 16.4 update. This could mean that Microsoft made a change to their implementation of the standard library or compiler that triggered this exception. More work with the debugger has revealed that the exception occurs during a vector get() operation. The operation is located in the TypedExpectation<F>* FindMatchingExpectationLocked(const ArgumentTuple& args) method within the gmock-spec-builders.h file. This observation further points to a change in the standard library.
I'm getting a similar issue, with Visual Studio 16.4.1, the application barfs with an invalid memory access inside std::_Iterator_base12::_Getcont() where _Myproxy was -1 (0xFFF...). The call stack involves TypedExpectation<F>* FindMatchingExpectationLocked(const ArgumentTuple& args) like the OP
I am getting the same issue /:
What do you mean that C++17 caused that? My project does not compile with c++14.
I made a small test project based on the code in my first post that was able to compile and run successfully with C++11 and C++14, but not C+++17. The project was able to compile successfully with all versions of the standard, but the exception only occurred when it was compiled with C++17. I've created a repo with the minimum required code that I was able to reproduce the bug with, feel free to clone it an try it out.
Also experiencing this issue.
Please upvote the issue at developer community portal, it may speed up fix if this is regression in msvc googlemock-crashes-when-compiling-with-c17
@alec500oo @pauluap @michalbali256 @Alexzxcvbnm Thank you for the report and the investigation.
The best way to approach this would be to create a proper PR and submit it for consideration. The maintainers do not use MSVC in day-to-day work and the only way to ensure that a particular version of this compiler can not handle a particular feature in the project is to include this version in the googletest CI.
Windows testing for googletest CI is done via Appveyor. I recommend including this version of the MSVC in appveyor.yml
This is codegen issue in MSVC and it already marked as _Fixed - Pending Release_
https://developercommunity.visualstudio.com/content/problem/847490/msvc-codegen-error-vector-reverse-iterator-x64-c17.html
Also having this issue with VS 2019 and C++17.
Most helpful comment
This is codegen issue in MSVC and it already marked as _Fixed - Pending Release_
https://developercommunity.visualstudio.com/content/problem/847490/msvc-codegen-error-vector-reverse-iterator-x64-c17.html