【问题标题】:incomplete type for std::any when GMOCKing interfaceGMOCKing 接口时 std::any 的不完整类型
【发布时间】:2019-08-02 20:16:56
【问题描述】:

我对这个 sn-p 有一个非常奇怪的编译问题:

#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

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> >'

如果我将 std::any 替换为 std::string 或任何其他常见类型,代码会编译。

【问题讨论】:

    标签: c++ gcc c++17 gmock


    【解决方案1】:

    这是 libstdc++ 错误90415

    我不确定导致此问题的 std::any 是什么。请注意,您的示例在使用 libstdc++ 时会失败,但在使用 libc++ 时会成功。

    【讨论】:

      【解决方案2】:

      关于此问题的其他信息,我有一个解决方法,可以在 gcc 9.1.0 中将 any 与 gmock 一起使用,使用 std::experimental::fundamentals_v1::any 而不是 std::any,它工作正常。

      【讨论】:

        猜你喜欢
        • 2014-07-21
        • 2019-09-13
        • 1970-01-01
        • 2018-11-08
        • 2012-05-12
        • 1970-01-01
        • 2015-05-07
        • 2018-01-24
        • 1970-01-01
        相关资源
        最近更新 更多