Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 460
Maksim Avatar asked Dec 01 '15 06:12

Maksim


1 Answers

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.

like image 84
Tanveer Gani Avatar answered Oct 05 '22 04:10

Tanveer Gani