[libcxx] r281641 - [libc++] Avoid <memory> include in locale_win32.h

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 15 11:36:13 PDT 2016


Author: smeenai
Date: Thu Sep 15 13:36:13 2016
New Revision: 281641

URL: http://llvm.org/viewvc/llvm-project?rev=281641&view=rev
Log:
[libc++] Avoid <memory> include in locale_win32.h

When `_LIBCPP_NO_EXCEPTIONS` is defined, we end up with compile errors
when targeting MSVCRT:

* Code includes `<new>`
* `<new>` includes `<cstdlib>` in order to get `abort`
* `<cstdlib>` includes `<stdlib.h>`, _before_ the `using ::abort`
* `<stdlib.h>` includes `locale_win32.h`
* `locale_win32.h` includes `<memory>`
* `<memory>` includes `<stdexcept>`
* `<stdexcept>` includes `<cstdlib` for `abort`, but that inclusion gets
  (correctly) ignored because of header guards
* `<stdexcept>` references `_VSTD::abort`, which isn't declared

The easiest solution is to make `locale_win32.h` not include `<memory>`,
by removing the use of `unique_ptr` and manually restoring the locale
instead.

Differential Revision: https://reviews.llvm.org/D24374

Modified:
    libcxx/trunk/include/support/win32/locale_win32.h
    libcxx/trunk/src/support/win32/locale_win32.cpp

Modified: libcxx/trunk/include/support/win32/locale_win32.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale_win32.h?rev=281641&r1=281640&r2=281641&view=diff
==============================================================================
--- libcxx/trunk/include/support/win32/locale_win32.h (original)
+++ libcxx/trunk/include/support/win32/locale_win32.h Thu Sep 15 13:36:13 2016
@@ -17,7 +17,6 @@ extern "C" unsigned short  __declspec(dl
 #include "support/win32/support.h"
 #include "support/win32/locale_mgmt_win32.h"
 #include <stdio.h>
-#include <memory>
 
 lconv *localeconv_l( locale_t loc );
 size_t mbrlen_l( const char *__restrict s, size_t n,
@@ -34,13 +33,10 @@ size_t wcsnrtombs_l( char *__restrict ds
                      size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc);
 wint_t btowc_l( int c, locale_t loc );
 int wctob_l( wint_t c, locale_t loc );
-typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
-typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 inline _LIBCPP_ALWAYS_INLINE
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
-  __locale_raii __current( uselocale(__l), uselocale );
-  return MB_CUR_MAX;
+  return ___mb_cur_max_l_func(__l);
 }
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+

Modified: libcxx/trunk/src/support/win32/locale_win32.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/locale_win32.cpp?rev=281641&r1=281640&r2=281641&view=diff
==============================================================================
--- libcxx/trunk/src/support/win32/locale_win32.cpp (original)
+++ libcxx/trunk/src/support/win32/locale_win32.cpp Thu Sep 15 13:36:13 2016
@@ -10,6 +10,11 @@
 
 #include <locale>
 #include <cstdarg> // va_start, va_end
+#include <memory>
+#include <type_traits>
+
+typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )




More information about the cfe-commits mailing list