I believe this is due to the "never-empty" guarantee of variant
: The default constructor of C
must initialize itself with a default-constructed value of its first template parameter - which is recursive_wrapper<A>
- and the default constructor of recursive_wrapper<A>
must initialize itself with a default-constructed instance of A
, which leads to infinite recursion.
Assuming you actually want a variant
that is either empty, or an instance of A
, you could introduce a dummy type as the variant's first parameter, for example:
struct variant_is_empty { };
using C = boost::variant<variant_is_empty, boost::recursive_wrapper<A>>;
EDIT: It appears you can use boost::recursive_wrapper
with boost::optional
, which would be easier than using variant
for the above case of an optional, recursive type.