[cfe-commits] [PATCH] [locale] fix diagnostic and function attributes

Howard Hinnant hhinnant at apple.com
Fri Dec 28 10:20:46 PST 2012


Modified version committed revision 171202.

Made use of -Wmissing-field-initializers identical to what is already being done for clang:

#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC   diagnostic ignored "-Wmissing-field-initializers"

The use of _LIBCPP_ALWAYS_INLINE isn't for performance but for ABI stability.  When the compiler gets to decide whether to inline code or not, and that code is part of the public API, then the ABI of the dylib changes on the compiler's decision.  With _LIBCPP_ALWAYS_INLINE libc++ manually controls its ABI.

In this particular case (countof), these are implementation details hidden by an unnamed namespace.  So they are not part of the ABI of libc++.  You got the right fix for the wrong reason. :-)

Howard


On Dec 27, 2012, at 11:56 PM, Saleem Abdulrasool <compnerd at compnerd.org> wrote:

> GCC complains about the template functions as potentially not being able to be
> inlined.  The original reason for _LIBCPP_ALWAYS_INLINE was to avoid the
> function call overhead for compilers which do not support constexpr (C++ 11).
> Switch to using a simple inline.  Disassembly seems to indicate that the
> function is inlined anyways.
> 
> Swap the order of the pragma push/ignore to push the state prior to ignoring the
> pragma.
> 
> 
> http://llvm-reviews.chandlerc.com/D249
> 
> Files:
>  src/locale.cpp
> 
> Index: src/locale.cpp
> ===================================================================
> --- src/locale.cpp
> +++ src/locale.cpp
> @@ -82,7 +82,7 @@
> }
> 
> template <typename T, size_t N>
> -_LIBCPP_ALWAYS_INLINE
> +inline
> _LIBCPP_CONSTEXPR
> size_t
> countof(const T (&)[N])
> @@ -91,7 +91,7 @@
> }
> 
> template <typename T>
> -_LIBCPP_ALWAYS_INLINE
> +inline
> _LIBCPP_CONSTEXPR
> size_t
> countof(const T * const begin, const T * const end)
> @@ -226,8 +226,8 @@
> 
> // NOTE(saleem) avoid the `base class should be explicitly initialized in the
> // copy constructor` warning emitted by GCC
> -#pragma GCC diagnostic ignored "-Wextra"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wextra"
> 
> locale::__imp::__imp(const __imp& other)
>     : facets_(max<size_t>(N, other.facets_.size())),
> @@ -4608,8 +4608,8 @@
> string
> __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
> {
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     tm t = {0};
> #pragma GCC diagnostic pop
>     t.tm_sec = 59;
> @@ -4757,8 +4757,8 @@
> wstring
> __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
> {
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     tm t = {0};
> #pragma GCC diagnositc pop
>     t.tm_sec = 59;
> @@ -4914,8 +4914,8 @@
> void
> __time_get_storage<char>::init(const ctype<char>& ct)
> {
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     tm t = {0};
> #pragma GCC diagnostic pop
>     char buf[100];
> @@ -4954,15 +4954,15 @@
> void
> __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
> {
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     tm t = {0};
> #pragma GCC diagnostic pop
>     char buf[100];
>     wchar_t wbuf[100];
>     wchar_t* wbe;
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     mbstate_t mb = {0};
> #pragma GCC diagnostic pop
>     // __weeks_
> @@ -5318,8 +5318,8 @@
>     char __nar[100];
>     char* __ne = __nar + 100;
>     __do_put(__nar, __ne, __tm, __fmt, __mod);
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     mbstate_t mb = {0};
> #pragma GCC diagnostic pop
>     const char* __nb = __nar;
> @@ -5846,8 +5846,8 @@
>         __thousands_sep_ = base::do_thousands_sep();
>     __grouping_ = lc->mon_grouping;
>     wchar_t wbuf[100];
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     mbstate_t mb = {0};
> #pragma GCC diagnostic pop
>     const char* bb = lc->currency_symbol;
> @@ -5932,8 +5932,8 @@
>         __thousands_sep_ = base::do_thousands_sep();
>     __grouping_ = lc->mon_grouping;
>     wchar_t wbuf[100];
> -#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
> #pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
>     mbstate_t mb = {0};
> #pragma GCC diagnostic pop
>     const char* bb = lc->int_curr_symbol;
> <D249.1.patch>




More information about the cfe-commits mailing list