diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1434,6 +1434,28 @@ # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ #endif +#define _LIBCPP_PRAGMA(text) _Pragma(#text) +#define _LIBCPP_FORCE_SEMICOLON static_assert(true, "") + +#if defined(__clang__) +# define _LIBCPP_DIAGNOSTIC_PUSH(reason) _LIBCPP_PRAGMA(clang diagnostic push) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_DIAGNOSTIC_POP() _LIBCPP_PRAGMA(clang diagnostic pop) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(warning) \ + _LIBCPP_PRAGMA(clang diagnostic ignored warning) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(warning) _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(warning) +#elif defined(__GNUG__) +# define _LIBCPP_DIAGNOSTIC_PUSH(reason) _LIBCPP_PRAGMA(GCC diagnostic push) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_DIAGNOSTIC_POP() _LIBCPP_PRAGMA(GCC diagnostic pop) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(warning) \ + _LIBCPP_PRAGMA(GCC diagnostic ignored warning) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(warning) _LIBCPP_FORCE_SEMICOLON +#else +# define _LIBCPP_DIAGNOSTIC_PUSH(reason) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_DIAGNOSTIC_POP() _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(warning) _LIBCPP_FORCE_SEMICOLON +# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(warning) _LIBCPP_FORCE_SEMICOLON +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG diff --git a/libcxx/include/__random/random_device.h b/libcxx/include/__random/random_device.h --- a/libcxx/include/__random/random_device.h +++ b/libcxx/include/__random/random_device.h @@ -28,10 +28,8 @@ #ifdef _LIBCPP_USING_DEV_RANDOM int __f_; #elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT) -# if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -# endif + _LIBCPP_DIAGNOSTIC_PUSH(); + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field"); // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we @@ -42,9 +40,7 @@ // ... vendors can add workarounds here if they switch to a different representation ... -# if defined(__clang__) -# pragma clang diagnostic pop -# endif + _LIBCPP_DIAGNOSTIC_POP(); #endif public: diff --git a/libcxx/include/exception b/libcxx/include/exception --- a/libcxx/include/exception +++ b/libcxx/include/exception @@ -189,15 +189,11 @@ class _LIBCPP_TYPE_VIS exception_ptr { -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-private-field" -#endif +_LIBCPP_DIAGNOSTIC_PUSH(); +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field"); void* __ptr1_; void* __ptr2_; -#if defined(__clang__) -#pragma clang diagnostic pop -#endif +_LIBCPP_DIAGNOSTIC_POP(); public: exception_ptr() _NOEXCEPT; exception_ptr(nullptr_t) _NOEXCEPT; diff --git a/libcxx/include/locale b/libcxx/include/locale --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -1486,10 +1486,10 @@ + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up + 2; // base prefix + terminating null character char __nar[__nbuf]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wformat-nonliteral" + _LIBCPP_DIAGNOSTIC_PUSH(); + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral"); int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); -#pragma clang diagnostic pop + _LIBCPP_DIAGNOSTIC_POP(); char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators @@ -1549,8 +1549,8 @@ char __nar[__nbuf]; char* __nb = __nar; int __nc; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wformat-nonliteral" + _LIBCPP_DIAGNOSTIC_PUSH(); + _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral"); if (__specify_precision) __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); @@ -1567,7 +1567,7 @@ __throw_bad_alloc(); __nbh.reset(__nb); } -#pragma clang diagnostic pop + _LIBCPP_DIAGNOSTIC_POP(); char* __ne = __nb + __nc; char* __np = this->__identify_padding(__nb, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators diff --git a/libcxx/src/future.cpp b/libcxx/src/future.cpp --- a/libcxx/src/future.cpp +++ b/libcxx/src/future.cpp @@ -29,13 +29,8 @@ return "future"; } -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wswitch" -#elif defined(__GNUC__) || defined(__GNUG__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wswitch" -#endif +_LIBCPP_DIAGNOSTIC_PUSH(); +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wswitch"); string __future_error_category::message(int ev) const @@ -58,11 +53,7 @@ return string("unspecified future_errc value\n"); } -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) || defined(__GNUG__) -#pragma GCC diagnostic pop -#endif +_LIBCPP_DIAGNOSTIC_POP(); const error_category& future_category() noexcept diff --git a/libcxx/src/hash.cpp b/libcxx/src/hash.cpp --- a/libcxx/src/hash.cpp +++ b/libcxx/src/hash.cpp @@ -11,9 +11,8 @@ #include "stdexcept" #include "type_traits" -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" -#endif +_LIBCPP_DIAGNOSTIC_PUSH(); +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare"); _LIBCPP_BEGIN_NAMESPACE_STD @@ -559,3 +558,5 @@ } _LIBCPP_END_NAMESPACE_STD + +_LIBCPP_DIAGNOSTIC_POP(); diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp --- a/libcxx/src/locale.cpp +++ b/libcxx/src/locale.cpp @@ -48,9 +48,8 @@ // On Linux, wint_t and wchar_t have different signed-ness, and this causes // lots of noise in the build log, but no bugs that I know of. -#if defined(__clang__) -#pragma clang diagnostic ignored "-Wsign-conversion" -#endif +_LIBCPP_DIAGNOSTIC_PUSH(); +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wsign-conversion"); _LIBCPP_BEGIN_NAMESPACE_STD @@ -5200,12 +5199,8 @@ { freelocale(__loc_); } -#if defined(__clang__) -#pragma clang diagnostic ignored "-Wmissing-field-initializers" -#endif -#if defined(__GNUG__) -#pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#endif + +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers"); template <> string @@ -5351,9 +5346,7 @@ return result; } -#if defined(__clang__) -#pragma clang diagnostic ignored "-Wmissing-braces" -#endif +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-braces"); #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <> @@ -6534,6 +6527,8 @@ #endif } +_LIBCPP_DIAGNOSTIC_POP(); + template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate; _LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate;)