Make locales (and transitively, std::endl) work reliably with gcc.
libc++ currently relies on undefined initialization order of global initializers when using gcc: 1. __start_std_streams in iostream.cpp calls locale:🆔:_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, let _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.) Also switch constexpr-specific code in bitset to use __SIZEOF_SIZE_T__ instead of __SIZE_WIDTH__, because gcc doesn't define the latter. Pair-programmed/debugged with Dana Jansens. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@210188 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -368,7 +368,14 @@ namespace std {
|
||||
#endif
|
||||
|
||||
#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
|
||||
// constexpr was added to GCC in 4.6.
|
||||
#if _GNUC_VER < 406
|
||||
#define _LIBCPP_HAS_NO_CONSTEXPR
|
||||
// Can only use constexpr in c++11 mode.
|
||||
#elif !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
|
||||
#define _LIBCPP_HAS_NO_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#define _NOEXCEPT throw()
|
||||
#define _NOEXCEPT_(x)
|
||||
|
Reference in New Issue
Block a user