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

后端 未结 4 1200
有刺的猬
有刺的猬 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:52

    VC++ compiler dev here.

    Peter Ruderman's answer is almost correct. The warning was really meant for constexpr objects where a constexpr constructor call is involved in the initialization. In Update1, we can now statically initialize literal types and some non-literal types with constexpr constructors but not all. Specifically, having virtual member functions will prevent static initialization even though the type has a constexpr constructor and is supplied with a constant initializer. The warning was meant to diagnose such cases. Unfortunately, there was a bug that caused it to fire when the types of the expressions in the initializer list had constexpr constructors (in the OP's example std::vector doesn't, but std::initializer_list does). This warning can be safely ignored since the compiler is not doing anything different from before.

    We've fixed the bug but unfortunately it was found too late to include in Update 1. In any case, the need for this warning should go away when we do a more complete implementation of constant initialization (3.6.2).

    Tanveer Gani Visual C++ Team.

提交回复
热议问题