`非静态数据成员之前需要构造函数` - 我是否使用 `boost::variant` 解决了 C++ 核心问题 1360?

`constructor required before non-static data member` - Am I hitting c++ core issue 1360 with a `boost::variant`?

使用此代码

#include <boost/variant.hpp>
#include <string>

struct Outer
{
    struct StateA
    {
        std::size_t index = std::string::npos;
    };

    struct StateB {};

    using State = boost::variant<StateA, StateB>;

    struct Inner
    {
        State state = StateB{};
    };
};

int main() {
    Outer o;
    (void)o;
}

我得到以下编译错误

/usr/include/boost/variant/variant.hpp:1301:17:   required from ‘class boost::variant<Outer::StateA, Outer::StateB>’
inner_class.cpp:18:30:   required from here
/usr/include/boost/type_traits/has_nothrow_constructor.hpp:27:84: error: constructor required before non-static data member for ‘Outer::StateA::index’ has been parsed
 template <class T> struct has_nothrow_constructor : public integral_constant<bool, BOOST_HAS_NOTHROW_CONSTRUCTOR(T)>{};

指的是this question, it would seem that I'm hitting this核心问题,但我想检查一下我的理解。

具体来说,我是在打

an order dependency that is not specified in the current text

当我的 typedefvariantInner 中初始化时?还是内部 structs 有其他原因导致此编译错误?

这不依赖于任何存在(发现)constexpr,因此它与 CWG1360 不同,但它肯定相似,因为它利用了不可能同时具有嵌套 [=16] =] 是一个完整的 class 上下文,因为它包含 class 并且嵌套 class 在包含 class 的定义之后才完整。也许最好的轨迹是 CWG2335,为此,已经提出了一般(长期)建议,即 class 中的实际依赖性应该通过类似实例化的机制进行跟踪;像你这样的例子要求这样的处理 across classes.