[libc++ patch] Make locales (and transitively, std::endl) work reliably with gcc

Nico Weber thakis at chromium.org
Wed Jun 4 08:54:51 PDT 2014


On Wed, Jun 4, 2014 at 5:19 AM, Marshall Clow <mclow.lists at gmail.com> wrote:

> On Jun 3, 2014, at 2:28 PM, Nico Weber <thakis at chromium.org> wrote:
>
> Ping?
>
>
> Is there some reason that you’re using __SIZEOF_SIZE_T__ instead of
> sizeof(size_t) ?
>

I believe sizeof can't be used in preprocessor lines (else the preprocessor
would have to call into sema to get the size, and sema doesn't know about
most types at preprocessing time yet.)


> Other than that, LGTM.
>

r210188, thanks!


>
> — Marshall
>
>
>
> On Mon, Jun 2, 2014 at 10:11 AM, Nico Weber <thakis at chromium.org> wrote:
>
>> Ping.
>>
>>
>> On Fri, May 30, 2014 at 4:04 PM, Nico Weber <thakis at chromium.org> wrote:
>>
>>> Hi,
>>>
>>> on trunk, libc++ relies on undefined initialization order of global
>>> initializers when using gcc:
>>>
>>> 1. __start_std_streams in iostream.cpp calls locale::id::_init, which
>>> assigns an id to each locale::facet in an initializer
>>>
>>> 2. Every facet has a static locale::id id, whose constructor sets the
>>> facet's id to 0*
>>>
>>> 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".
>>>
>>> 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.)
>>>
>>> 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.
>>>
>>> Pair-programmed/debugged with Dana Jansens.
>>>
>>> Nico
>>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140604/b7cff413/attachment.html>


More information about the cfe-commits mailing list