I got this reproduced down to:
```cpp class Class { public: void member(bool) {}; };
namespace {
struct MockClass : public Class { MOCK_METHOD1(member, void(bool)); };
}
TEST(Test, tests) { MockClass object; EXPECT_CALL(object, member(testing::_)); } ```
The cmake_pch.hxx:
```cpp /* generated by CMake */
#pragma GCC system_header #ifdef __cplusplus #include <gmock/gmock.h> #include <gtest/gtest.h> #include <vector> #include <string> #include <exception> #include <memory> #endif // __cplusplus ```
The compiler command:
``` /usr/bin/g++-12 -DBOOST_ALL_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DEGL_NO_X11 -DGTEST_VERSION_MAJOR=1 -DGTEST_VERSION_MINOR=12 -DGTEST_VERSION_PATCH=1 -DLTTNG_UST_HAVE_SDT_INTEGRATION -DMESA_EGL_NO_X11_HEADERS -DMIR_BUILD_PLATFORM_GBM_KMS -DMIR_DRMMODEADDFB_HAS_CONST_SIGNATURE -DMIR_VERSION_MAJOR=2 -DMIR_VERSION_MICRO=0 -DMIR_VERSION_MINOR=8 -D_FILE_OFFSET_BITS=64 -I/usr/src/googletest/googlemock/include -O2 -ffat-lto-objects -pthread -fPIC -std=c++20 -include /home/ubuntu/mir/build-arm64/tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/cmake_pch.hxx -c tmp.cpp
In file included from /usr/include/c++/12/ios:40, from /usr/include/c++/12/ostream:38, from /usr/include/c++/12/bits/unique_ptr.h:41, from /usr/include/c++/12/memory:76, from /usr/src/googletest/googlemock/include/gmock/gmock-actions.h:139, from /usr/src/googletest/googlemock/include/gmock/gmock.h:56, from /home/ubuntu/mir/build-arm64/tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/cmake_pch.hxx:5, from <command-line>: In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char _traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43, inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/googletest/goog lemock/include/gmock/gmock-spec-builders.h:1278:23, inlined from ‘virtual void Test_tests_Test::TestBody()’ at tmp.cpp:20:5: /usr/include/c++/12/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 19 bytes into a region of size 16 overflows the destination [-Wstringop-ove rflow=] 431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ In file included from /usr/src/googletest/googlemock/include/gmock/gmock-function-mocker.h:43, from /usr/src/googletest/googlemock/include/gmock/gmock.h:58: /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void Test_tests_Test::TestBody()’: /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:63: note: at offset 16 into destination object ‘<anonymous>’ of size 32 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char _traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43, inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/googletest/goog lemock/include/gmock/gmock-spec-builders.h:1278:23, inlined from ‘virtual void Test_tests_Test::TestBody()’ at tmp.cpp:20:5: /usr/include/c++/12/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 21 bytes into a region of size 16 overflows the destination [-Wstringop-ove rflow=] 431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void Test_tests_Test::TestBody()’: /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:69: note: at offset 16 into destination object ‘<anonymous>’ of size 32 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~ In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char _traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43, inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/googletest/goog lemock/include/gmock/gmock-spec-builders.h:1278:23, inlined from ‘virtual void Test_tests_Test::TestBody()’ at tmp.cpp:20:5: /usr/include/c++/12/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 39 bytes into a region of size 16 overflows the destination [-Wstringop-ove rflow=] 431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void Test_tests_Test::TestBody()’: /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:76: note: at offset 16 into destination object ‘<anonymous>’ of size 32 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 1279 | call + ")"); | ~~~~ In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char _traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43, inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/googletest/goog lemock/include/gmock/gmock-spec-builders.h:1278:23, inlined from ‘virtual void Test_tests_Test::TestBody()’ at tmp.cpp:20:5: /usr/include/c++/12/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 40 bytes into a region of size 16 overflows the destination [-Wstringop-ove rflow=] 431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void Test_tests_Test::TestBody()’: /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:23: note: at offset 16 into destination object ‘source_text’ of size 32 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + | ^~~~~~~~~~~ ```
Now, anything I change in the command above, it will then compile, because it will not use the precompiled headers.
I got this reproduced down to:
```cpp
class Class
{
public:
void member(bool) {};
};
namespace
{
struct MockClass : public Class METHOD1( member, void(bool));
{
MOCK_
};
}
TEST(Test, tests) CALL(object, member( testing: :_));
{
MockClass object;
EXPECT_
}
```
The cmake_pch.hxx:
```cpp
/* generated by CMake */
#pragma GCC system_header
#ifdef __cplusplus
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <vector>
#include <string>
#include <exception>
#include <memory>
#endif // __cplusplus
```
The compiler command:
``` DATE_TIME_ DYN_LINK -DBOOST_ FILESYSTEM_ DYN_LINK -DBOOST_ IOSTREAMS_ DYN_LINK -DBOOST_ PROGRAM_ OPTIONS_ DYN_LINK -DBOOST_ SYSTEM_ DYN_LINK -DEGL_NO_X11 -DGTEST_ VERSION_ MAJOR=1 -DGTEST_ VERSION_ MINOR=12 -DGTEST_ VERSION_ PATCH=1 -DLTTNG_ UST_HAVE_ SDT_INTEGRATION -DMESA_ EGL_NO_ X11_HEADERS -DMIR_BUILD_ PLATFORM_ GBM_KMS -DMIR_DRMMODEAD DFB_HAS_ CONST_SIGNATURE -DMIR_VERSION_ MAJOR=2 -DMIR_VERSION_ MICRO=0 -DMIR_VERSION_ MINOR=8 -D_FILE_ OFFSET_ BITS=64 -I/usr/ src/googletest/ googlemock/ include -O2 -ffat-lto-objects -pthread -fPIC -std=c++20 -include /home/ubuntu/ mir/build- arm64/tests/ acceptance- tests/CMakeFile s/mir_acceptanc e_tests. dir/cmake_ pch.hxx -c tmp.cpp
/usr/bin/g++-12 -DBOOST_ALL_NO_LIB -DBOOST_
In file included from /usr/include/ c++/12/ ios:40,
from /usr/include/ c++/12/ ostream: 38,
from /usr/include/ c++/12/ bits/unique_ ptr.h:41,
from /usr/include/ c++/12/ memory: 76,
from /usr/src/ googletest/ googlemock/ include/ gmock/gmock- actions. h:139,
from /usr/src/ googletest/ googlemock/ include/ gmock/gmock. h:56,
from /home/ubuntu/ mir/build- arm64/tests/ acceptance- tests/CMakeFile s/mir_acceptanc e_tests. dir/cmake_ pch.hxx: 5,
from <command-line>: traits< char>:: char_type* std::char_ traits< char>:: copy(char_ type*, const char_type*, std::size_t)’, cxx11:: basic_string< _CharT, _Traits, _Alloc> ::basic_ string( std::__ cxx11:: basic_string< _CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_ traits< char>; char>]’ at /usr/include/ c++/12/ bits/basic_ string. h:674:23, cxx11:: basic_string< _CharT, _Traits, _Allocator> std::operator+ (__cxx11: :basic_ string< _CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char c++/12/ bits/basic_ string. h:3554: 43, :internal: :TypedExpectati on<F>& testing: :internal: :MockSpec< F>::InternalExp ectedAt( const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/ googletest/ goog include/ gmock/gmock- spec-builders. h:1278: 23, Test::TestBody( )’ at tmp.cpp:20:5: c++/12/ bits/char_ traits. h:431:56: warning: ‘void* __builtin_ memcpy( void*, const void*, long unsigned int)’ writing 19 bytes into a region of size 16 overflows the destination [-Wstringop-ove cast<char_ type*>( __builtin_ memcpy( __s1, __s2, __n)); ~~~~~~~ ~~^~~~~ ~~~~~~~ ~~~~~ googletest/ googlemock/ include/ gmock/gmock- function- mocker. h:43,
from /usr/src/ googletest/ googlemock/ include/ gmock/gmock. h:58: googletest/ googlemock/ include/ gmock/gmock- spec-builders. h: In member function ‘virtual void Test_tests_ Test::TestBody( )’: googletest/ googlemock/ include/ gmock/gmock- spec-builders. h:1278: 63: note: at offset 16 into destination object ‘<anonymous>’ of size 32 text(std: :string( "EXPECT_ CALL(") + obj + ", " + ~~~~~~~ ~~~~~~~ ~~^~~~~ traits< char>:: char_type* std::char_ traits< char>:: copy(char_ type*, const char_type*, std::size_t)’, cxx11:: basic_string< _CharT, _Traits, _Alloc> ::basic_ string( std::__ cxx11:: basic_string< _CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_ traits< char>; char>]’ at /usr/include/ c++/12/ bits/basic_ string. h:674:23, cxx11:: basic_string< _CharT, _Traits, _Allocator> std::operator+ (__cxx11: :basic_ string< _CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char c++/12/ bits/basic_ string. h:3554: 43, :internal: :TypedExpectati on<F>& testing: :internal: :MockSpec< F>::InternalExp ectedAt( const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/ googletest/ goog include/ gmock/gmock- spec-builders. h:1278: 23, Test::TestBody( )’ at tmp.cpp:20:5: c++/12/ bits/char_ traits. h:431:56: warning: ‘void* __builtin_ memcpy( void*, const void*, long unsigned int)’ writing 21 bytes into a region of size 16 overflows the destination [-Wstringop-ove cast<char_ type*>( __builtin_ memcpy( __s1, __s2, __n)); ~~~~~~~ ~~^~~~~ ~~~~~~~ ~~~~~ googletest/ googlemock/ include/ gmock/gmock- spec-builders. h: In member function ‘virtual void Test_tests_ Test::TestBody( )’: googletest/ googlemock/ include/ gmock/gmock- spec-builders. h:1278: 69: note: at offset 16 into destination object ‘<anonymous>’ of size 32 text(std: :string( "EXPECT_ CALL(") + obj + ", " + ~~~~~~~ ~~~~~~~ ~~~~~~~ ~^~~~~~ traits< char>:: char_type* std::char_ traits< char>:: copy(char_ type*, const char_type*, std::size_t)’, cxx11:: basic_string< _CharT, _Traits, _Alloc> ::basic_ string( std::__ cxx11:: basic_string< _CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_ traits< char>; char>]’ at /usr/include/ c++/12/ bits/basic_ string. h:674:23, cxx11:: basic_string< _CharT, _Traits, _Allocator> std::operator+ (__cxx11: :basic_ string< _CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char c++/12/ bits/basic_ string. h:3554: 43, :internal: :TypedExpectati on<F>& testing: :internal: :MockSpec< F>::InternalExp ectedAt( const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/ googletest/ goog include/ gmock/gmock- spec-builders. h:1278: 23, Test::TestBody( )’ at tmp.cpp:20:5: c++/12/ bits/char_ traits. h:431:56: warning: ‘void* __builtin_ memcpy( void*, const void*, long unsigned int)’ writing 39 bytes into a region of size 16 overflows the destination [-Wstringop-ove cast<char_ type*>( __builtin_ memcpy( __s1, __s2, __n)); ~~~~~~~ ~~^~~~~ ~~~~~~~ ~~~~~ googletest/ googlemock/ include/ gmock/gmock- spec-builders. h: In member function ‘virtual void Test_tests_ Test::TestBody( )’: googletest/ googlemock/ include/ gmock/gmock- spec-builders. h:1278: 76: note: at offset 16 into destination object ‘<anonymous>’ of size 32 text(std: :string( "EXPECT_ CALL(") + obj + ", " + ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~^ traits< char>:: char_type* std::char_ traits< char>:: copy(char_ type*, const char_type*, std::size_t)’, cxx11:: basic_string< _CharT, _Traits, _Alloc> ::basic_ string( std::__ cxx11:: basic_string< _CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_ traits< char>; char>]’ at /usr/include/ c++/12/ bits/basic_ string. h:674:23, cxx11:: basic_string< _CharT, _Traits, _Allocator> std::operator+ (__cxx11: :basic_ string< _CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char c++/12/ bits/basic_ string. h:3554: 43, :internal: :TypedExpectati on<F>& testing: :internal: :MockSpec< F>::InternalExp ectedAt( const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/ googletest/ goog include/ gmock/gmock- spec-builders. h:1278: 23, Test::TestBody( )’ at tmp.cpp:20:5: c++/12/ bits/char_ traits. h:431:56: warning: ‘void* __builtin_ memcpy( void*, const void*, long unsigned int)’ writing 40 bytes into a region of size 16 overflows the destination [-Wstringop-ove cast<char_ type*>( __builtin_ memcpy( __s1, __s2, __n)); ~~~~~~~ ~~^~~~~ ~~~~~~~ ~~~~~ googletest/ googlemock/ include/ gmock/gmock- spec-builders. h: In member function ‘virtual void Test_tests_ Test::TestBody( )’: googletest/ googlemock/ include/ gmock/gmock- spec-builders. h:1278: 23: note: at offset 16 into destination object ‘source_text’ of size 32 text(std: :string( "EXPECT_ CALL(") + obj + ", " +
In static member function ‘static constexpr std::char_
inlined from ‘constexpr std::__
_Alloc = std::allocator<
inlined from ‘constexpr std::__
_traits<char>; _Alloc = allocator<char>]’ at /usr/include/
inlined from ‘testing:
lemock/
inlined from ‘virtual void Test_tests_
/usr/include/
rflow=]
431 | return static_
| ~~~~~~~
In file included from /usr/src/
/usr/src/
/usr/src/
1278 | const std::string source_
| ~~~~~~~
In static member function ‘static constexpr std::char_
inlined from ‘constexpr std::__
_Alloc = std::allocator<
inlined from ‘constexpr std::__
_traits<char>; _Alloc = allocator<char>]’ at /usr/include/
inlined from ‘testing:
lemock/
inlined from ‘virtual void Test_tests_
/usr/include/
rflow=]
431 | return static_
| ~~~~~~~
/usr/src/
/usr/src/
1278 | const std::string source_
| ~~~~~~~
In static member function ‘static constexpr std::char_
inlined from ‘constexpr std::__
_Alloc = std::allocator<
inlined from ‘constexpr std::__
_traits<char>; _Alloc = allocator<char>]’ at /usr/include/
inlined from ‘testing:
lemock/
inlined from ‘virtual void Test_tests_
/usr/include/
rflow=]
431 | return static_
| ~~~~~~~
/usr/src/
/usr/src/
1278 | const std::string source_
| ~~~~~~~
1279 | call + ")");
| ~~~~
In static member function ‘static constexpr std::char_
inlined from ‘constexpr std::__
_Alloc = std::allocator<
inlined from ‘constexpr std::__
_traits<char>; _Alloc = allocator<char>]’ at /usr/include/
inlined from ‘testing:
lemock/
inlined from ‘virtual void Test_tests_
/usr/include/
rflow=]
431 | return static_
| ~~~~~~~
/usr/src/
/usr/src/
1278 | const std::string source_
| ^~~~~~~~~~~
```
Now, anything I change in the command above, it will then compile, because it will not use the precompiled headers.