vso*_*tco 2 c++ clang incomplete-type c++11 gcc5
考虑与先前SO问题C++循环依赖混淆相关的代码与邻接列表表示
#include <cstddef>
#include <unordered_set>
class Node;
class Hash {
public:
std::size_t operator()(const Node &node) const;
};
class Node {
public:
int data;
std::unordered_set<Node, Hash> links;
};
inline size_t Hash::operator()(const Node &node) const {
return node.data;
}
int main()
{
}
Run Code Online (Sandbox Code Playgroud)
使用g ++ 4.9.2或g ++ 5时,此代码无法编译,但是使用clang ++ 3.5进行编译.
g ++吐出的错误始于
error: invalid application of 'sizeof' to incomplete type 'Node': std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>
问:是否Node有一个声明的时候是一个完整的类型std::unordered_set?看起来g ++或clang ++在这种情况下是错误的.
PS:我知道这种情况可以通过使用a std::shared_ptr<Node>来避免,但是想了解上面代码中的行为.