error C4592: symbol will be dynamically initialized. VS2015.1 static const std::vector field

后端 未结 4 1214
有刺的猬
有刺的猬 2021-02-13 00:17

after update VS2015.1 next code no longer compiles:

class testClass
{
static const std::vector test;
};

initialization



        
4条回答
  •  遇见更好的自我
    2021-02-13 00:40

    Unfortunately, I don't have enough "reputation" to comment, so I'll add my comments here.

    @Peter Ruderman: complete support for constant initialization is on the list. I can't say yet whether it'll make it into Update 2 but we'll do our best. You're getting a warning for a type without constexpr constructors because of the bug which detected a different constexpr constructor in the call-tree. This usually comes from std::initializer_list<>.

    @Peter Ruderman: Also, a slight correction: for static lifetime objects initialized with a constexpr constructor call, static initialization is required only if the initializer is a constant-initializer, i.e., consists only of constant expressions. Update1 does this for but not for types containing virtual functions.

    Also: in the OP's code, no static initialization is required, though I suppose a compiler can do it for quality-of-implementation reasons. This is because 'const' was used rather than 'constexpr', the latter requiring static initialization.

    To reiterate: disabling this warning is perfectly reasonable (and safe).

提交回复
热议问题