incomplete type for std::any when GMOCKing interface

落爺英雄遲暮 提交于 2020-01-11 12:35:35

问题


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.


回答1:


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++.




回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!