I would expect the following code to give a segmentation error (or otherwise UB):
struct T { T(); }; T t; char const* str = "Test string"; T::T() { std::cout << str;
This is because t initialized to str . I expect str to keep the value (char const*)0 due to zero initialization. My interpretation of [C++11: 3.6.2/2] supports this.
However , the above snippet displays the string as expected (and I confirmed this behavior by also printing the pointer value).
Is there some static initialization rule that is missing here, which allows str initialize the value before t starts? Where is it in the standard?
This caused a static change of variables during the build , where the responder claimed that using char const* rather than std::string to statically avoid the static initialization fiasco. I did not agree, but now I am not sure ...
source share