I have a very weird compilation problem with this snippet:
#include <any>
#include <gmock/gmock.h>
struct Class
{
virtual std::any get(int, int) = 0;
};
struct MockClass: Class
{
MOCK_METHOD2(get, std::any(int, int));
};
int foo()
{
MockClass dd;
}
Error gcc 9.1.0:
/usr/include/c++/9.1.0/type_traits:131:12: error: incomplete type ‘std::is_copy_constructible<testing::internal::ReferenceOrValueWrapper<std::any> >’ used in nested name specifier
clang 8.0.0:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/type_traits:132:31: error: no member named 'value' in 'std::is_copy_constructible<testing::internal::ReferenceOrValueWrapper<std::any> >'
If I replace std::any
with std::string
or any other common type, code compiles.
This is libstdc++ bug 90415.
I am not sure what it is about std::any
that causes this problem. Note that your example fails on clang using libstdc++, but succeeds when using libc++.
Additional information about this issue, that I have got a workaround to use any
with gmock in gcc 9.1.0, use std::experimental::fundamentals_v1::any
instead of std::any
, and it works fine.
来源:https://stackoverflow.com/questions/57332965/incomplete-type-for-stdany-when-gmocking-interface