after update VS2015.1 next code no longer compiles:
class testClass
{
static const std::vector<int> test;
};
initialization
const std::vector<int> testClass::test =
{
1,2
};
with error:
error C4592: 'test': symbol will be dynamically initialized (implementation limitation)
is it bug or something has changed in the compiler?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With