<div dir="ltr">Ping.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 30, 2014 at 4:04 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>on trunk, libc++ relies on undefined initialization order of global initializers when using gcc:</div>
<div><br></div><div>1. __start_std_streams in iostream.cpp calls locale::id::_init, which assigns an id to each locale::facet in an initializer</div>
<div><br></div><div>2. Every facet has a static locale::id id, whose constructor sets the facet's id to 0*</div><div><br></div><div>If 2 runs after 1, it clobbers the facet's assigned consecutive id, causing exceptions to be thrown when e.g. running code like "cout << endl".</div>

<div><br></div><div>To fix this, the attached patch lets _LIBCPP_CONSTEXPR evaluate to "constexpr" instead of nothing with gcc. locale::id's constructor is marked _LIBCPP_CONSTEXPR, which ensures that it won't get an initializer that could potentially run after the iostream.cpp initializer. (This remains broken when building with msvc.)</div>

<div><br></div><div>Once _LIBCPP_CONSTEXPR is available, bitset fails to compile since gcc doesn't define __SIZE_WIDTH__, so switch bitset to use __SIZEOF_SIZE_T__ which both clang and gcc define.</div><div><br></div>

<div>Pair-programmed/debugged with Dana Jansens.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Nico</div>























</font></span></div>
</blockquote></div><br></div>