Is the following legal?
template< typename T >
struct tree_node
{
T t;
std::vector<tree_node> children;
};
A comment to this post seems to suggest that it is not.
EDIT: This doesn't strike me as an "undefined behavior" type of scenario. The intended semantics are unambiguous. If it is an invalid usage of an incomplete type then it should be a compile-time error.
In my tests this seems to work fine (I have used both GCC and Clang -- both with -Wall -Werror -std=c++11
).
Is there something in the language definition (prior to C++17) that directly or indirectly specifies this as undefined behavior, or is it just under-specified?
Keep in mind that this is very similar, structurally, to something like the following:
typedef int T;
struct tree_node;
struct tree_node
{
T t;
tree_node * children;
}
See Question&Answers more detail:os