包括 gtest 头文件会导致模板类函数调用崩溃

huangapple go评论64阅读模式
英文:

Including gtest header crashes templated Class Function call

问题

I have a problem regarding including gtest header into my programm. The following code compiles as long as the gtest header is commented out, as soon as the header is pulled, the compiler throws an error:

#include "gtest/gtest.h"

#include <queue>
#include <nlohmann/json.hpp>


struct Data {};
nlohmann::json &operator<<(nlohmann::json &json, const Data &) {
    return json;
}

template <typename T_data>
class Buffer{
public:
    Buffer(){};

    void FlushBuffer(){
        nlohmann::json out_json;
        out_json[0] << record_;
    };
private:
   T_data record_;
};

class LineRingBufferTest : public Buffer<Data>  {
public:
    LineRingBufferTest() :  Buffer<Data>(){
        Buffer<Data>::FlushBuffer();
    }
};

Tested with gcc 12.2 / clang 1:11.0-51+nmu5 on (docker gcc:12.2-bullseye)

Thrown error is:

/usr/local/include/c++/12.2.0/type_traits:1135:52: note: 'std::__is_complete_or_unbounded<__type_identity<testing::internal::Secret>>((std::__type_identity<testing::internal::Secret>(), std::__type_identity<testing::internal::Secret>()))' evaluates to false
...
/usr/local/include/c++/12.2.0/type_traits:980:52: error: static assertion failed: template argument must be a complete class or an unbounded array

I have no clue what exactly is going on here.
Thanks a lot in advance.

英文:

i have a problem regarding including gtest header into my programm. The following code compiles as long as the gtest header is commented out, as soon as the header is pulled, the compiler throws an error:

#include &quot;gtest/gtest.h&quot;

#include &lt;queue&gt;
#include &lt;nlohmann/json.hpp&gt;


struct Data {};
nlohmann::json &amp;operator&lt;&lt;(nlohmann::json &amp;json, const Data &amp;) {
    return json;
}

template &lt;typename T_data&gt;
class Buffer{
public:
    Buffer(){};

    void FlushBuffer(){
        nlohmann::json out_json;
        out_json[0] &lt;&lt; record_;
    };
private:
   T_data record_;
};

class LineRingBufferTest : public Buffer&lt;Data&gt;  {
public:
    LineRingBufferTest() :  Buffer&lt;Data&gt;(){
        Buffer&lt;Data&gt;::FlushBuffer();
    }
};

Tested with gcc 12.2 / clang 1:11.0-51+nmu5 on (docker gcc:12.2-bullseye)

Thrown error is:

/usr/local/include/c++/12.2.0/type_traits:1135:52: note: &#39;std::__is_complete_or_unbounded&lt;__type_identity&lt;testing::internal::Secret&gt; &gt;((std::__type_identity&lt;testing::internal::Secret&gt;(), std::__type_identity&lt;testing::internal::Secret&gt;()))&#39; evaluates to false
...
/usr/local/include/c++/12.2.0/type_traits:980:52: error: static assertion failed: template argument must be a complete class or an unbounded array

I have no clue what exactly is going on here.
Thanks a lot in advance.

答案1

得分: 2

这是一个GoogleTest的问题。今天已经修复了,在这里
尝试更新GoogleTest的main分支。

英文:

This was GoogeTest issue. It was fixed today here.
> Resolve an issue where the resolution of operator&lt;&lt; overloads would
> attempt to instantiate the incomplete testing::internal::Secret type.

Try to update GoogeTest main branch.

huangapple
  • 本文由 发表于 2023年6月12日 20:07:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76456525.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定