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

后端 未结 4 656
情深已故
情深已故 2021-02-13 00:02

after update VS2015.1 next code no longer compiles:

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

initialization



        
4条回答
  •  抹茶落季
    2021-02-13 00:57

    I believe that the warning is triggered by new logic for detecting when the compiler generates dynamic initializers for static objects with constexpr constructors. It doesn't make sense to raise it in this particular case because std::vector has no constexpr constructors. So that's bug number 1.

    Bug number 2 is that static objects with constexpr constructors still get dynamic initializers. This was supposed to be fixed in update 1 but apparently Microsoft was unable to do it.

    When you initialize a type with a constexpr constructor at module level, the compiler should be able to run the constructor itself and embed the fully constructed object directly in your image file. This doesn't currently work in VC, however. Instead it will create a dynamic initializer and initialize the object at runtime when your program first starts.

    The warning is trying to make this problem visible. It's safe to ignore in most cases, and it's certainly safe to ignore in this specific case.

提交回复
热议问题