英文:
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 "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.
答案1
得分: 2
这是一个GoogleTest的问题。今天已经修复了,在这里。
尝试更新GoogleTest的main
分支。
英文:
This was GoogeTest issue. It was fixed today here.
> Resolve an issue where the resolution of operator<<
overloads would
> attempt to instantiate the incomplete testing::internal::Secret
type.
Try to update GoogeTest main
branch.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论