GMOCKing 接口时 std::any 的不完整类型
incomplete type for std::any when GMOCKing interface
这个片段有一个非常奇怪的编译问题:
#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;
}
错误 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
叮当声 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> >'
如果我将 std::any
替换为 std::string
或任何其他常见类型,代码将编译。
这是 libstdc++ 错误 90415。
我不确定 std::any
是什么导致了这个问题。请注意,您的示例使用 libstdc++ 在 clang 上失败,但在使用 libc++ 时成功。
有关此问题的其他信息,我有一个在 gcc 9.1.0 中将 any
与 gmock 一起使用的解决方法,使用 std::experimental::fundamentals_v1::any
而不是 std::any
,它工作正常.
这个片段有一个非常奇怪的编译问题:
#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;
}
错误 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
叮当声 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> >'
如果我将 std::any
替换为 std::string
或任何其他常见类型,代码将编译。
这是 libstdc++ 错误 90415。
我不确定 std::any
是什么导致了这个问题。请注意,您的示例使用 libstdc++ 在 clang 上失败,但在使用 libc++ 时成功。
有关此问题的其他信息,我有一个在 gcc 9.1.0 中将 any
与 gmock 一起使用的解决方法,使用 std::experimental::fundamentals_v1::any
而不是 std::any
,它工作正常.