[libc++] Guard warning pragmas
This makes the GCC output even cleaner!
Reviewed By: ldionne, #libc
Spies: mstorsjo, Quuxplusone, Mordante, libcxx-commits
Differential Revision: https://reviews.llvm.org/D119295
NOKEYCHECK=True
GitOrigin-RevId: a7c2a6289c22624f8b21b6c0e3f27047c4d4113d
diff --git a/src/future.cpp b/src/future.cpp
index 177fe75..07ae938 100644
--- a/src/future.cpp
+++ b/src/future.cpp
@@ -29,13 +29,9 @@
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_CLANG_DIAGNOSTIC_IGNORED("-Wswitch")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wswitch")
string
__future_error_category::message(int ev) const
@@ -58,11 +54,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/src/hash.cpp b/src/hash.cpp
index b8e921a..daf276f 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -11,9 +11,7 @@
#include "stdexcept"
#include "type_traits"
-#ifdef __clang__
-#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
-#endif
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare")
_LIBCPP_BEGIN_NAMESPACE_STD
diff --git a/src/locale.cpp b/src/locale.cpp
index 56b1a4b..3f8a261 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -49,9 +49,7 @@
// 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_CLANG_DIAGNOSTIC_IGNORED("-Wsign-conversion")
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -5201,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
@@ -5352,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 <>
diff --git a/src/support/win32/locale_win32.cpp b/src/support/win32/locale_win32.cpp
index 43e5c9a..67f4d13 100644
--- a/src/support/win32/locale_win32.cpp
+++ b/src/support/win32/locale_win32.cpp
@@ -97,10 +97,10 @@
ret, n, format, loc, ap);
#else
__libcpp_locale_guard __current(loc);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-nonliteral"
+ _LIBCPP_DIAGNOSTIC_PUSH
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
int result = vsnprintf( ret, n, format, ap );
-#pragma clang diagnostic pop
+ _LIBCPP_DIAGNOSTIC_POP
#endif
va_end(ap);
return result;
diff --git a/src/support/win32/support.cpp b/src/support/win32/support.cpp
index 6d4b371..dbec408 100644
--- a/src/support/win32/support.cpp
+++ b/src/support/win32/support.cpp
@@ -23,10 +23,10 @@
// Query the count required.
va_list ap_copy;
va_copy(ap_copy, ap);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-nonliteral"
+ _LIBCPP_DIAGNOSTIC_PUSH
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
int count = vsnprintf( NULL, 0, format, ap_copy );
-#pragma clang diagnostic pop
+ _LIBCPP_DIAGNOSTIC_POP
va_end(ap_copy);
if (count < 0)
return count;
@@ -36,10 +36,10 @@
return -1;
// If we haven't used exactly what was required, something is wrong.
// Maybe bug in vsnprintf. Report the error and return.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-nonliteral"
+ _LIBCPP_DIAGNOSTIC_PUSH
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
if (vsnprintf(p, buffer_size, format, ap) != count) {
-#pragma clang diagnostic pop
+ _LIBCPP_DIAGNOSTIC_POP
free(p);
return -1;
}