[libcxx-commits] [libcxx] 14324fa - [libc++] Add warning pragma macros in the test suite
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 16 16:11:28 PDT 2022
Author: Nikolas Klauser
Date: 2022-03-17T00:11:20+01:00
New Revision: 14324fa4285f5cd1e421a6cebdceb05d6c49a8dc
URL: https://github.com/llvm/llvm-project/commit/14324fa4285f5cd1e421a6cebdceb05d6c49a8dc
DIFF: https://github.com/llvm/llvm-project/commit/14324fa4285f5cd1e421a6cebdceb05d6c49a8dc.diff
LOG: [libc++] Add warning pragma macros in the test suite
Reviewed By: ldionne, #libc, EricWF
Spies: EricWF, libcxx-commits
Differential Revision: https://reviews.llvm.org/D121552
Added:
Modified:
libcxx/src/filesystem/filesystem_common.h
libcxx/test/libcxx/containers/associative/undef_min_max.pass.cpp
libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp
libcxx/test/libcxx/numerics/c.math/undef_min_max.pass.cpp
libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp
libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp
libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp
libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp
libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/move_assign.pass.cpp
libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/move_assign.pass.cpp
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp
libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
libcxx/test/std/library/description/conventions/expos.only.func/synth_three_way.pass.cpp
libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
libcxx/test/std/numerics/c.math/cmath.pass.cpp
libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
libcxx/test/std/ranges/range.factories/range.iota.view/ctor.value.bound.pass.cpp
libcxx/test/std/ranges/range.factories/range.iota.view/end.pass.cpp
libcxx/test/std/ranges/range.factories/range.iota.view/iterator/star.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/noncopyable_return_type.pass.cpp
libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp
libcxx/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp
libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp
libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp
libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
libcxx/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
libcxx/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
libcxx/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/three_way.pass.cpp
libcxx/test/support/charconv_test_helpers.h
libcxx/test/support/count_new.h
libcxx/test/support/test_macros.h
libcxx/test/support/unique_ptr_test_helper.h
Removed:
################################################################################
diff --git a/libcxx/src/filesystem/filesystem_common.h b/libcxx/src/filesystem/filesystem_common.h
index c98d14416c8b6..c9bc998007a66 100644
--- a/libcxx/src/filesystem/filesystem_common.h
+++ b/libcxx/src/filesystem/filesystem_common.h
@@ -25,16 +25,14 @@
# define WIN32_LEAN_AND_MEAN
# define NOMINMAX
# include <windows.h>
-#endif
-
-#if !defined(_LIBCPP_WIN32API)
+#else
# include <dirent.h> // for DIR & friends
# include <fcntl.h> /* values for fchmodat */
# include <sys/stat.h>
# include <sys/statvfs.h>
# include <sys/time.h> // for ::utimes as used in __last_write_time
# include <unistd.h>
-#endif
+#endif // defined(_LIBCPP_WIN32API)
#include "../include/apple_availability.h"
@@ -46,10 +44,9 @@
#endif
#endif
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-function"
-#endif
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function")
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function")
#if defined(_LIBCPP_WIN32API)
#define PS(x) (L##x)
@@ -611,4 +608,6 @@ static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
_LIBCPP_END_NAMESPACE_FILESYSTEM
+_LIBCPP_DIAGNOSTIC_POP
+
#endif // FILESYSTEM_COMMON_H
diff --git a/libcxx/test/libcxx/containers/associative/undef_min_max.pass.cpp b/libcxx/test/libcxx/containers/associative/undef_min_max.pass.cpp
index ff15f355f8255..e28fb14c11a68 100644
--- a/libcxx/test/libcxx/containers/associative/undef_min_max.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/undef_min_max.pass.cpp
@@ -6,17 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-W#warnings"
-#endif
-
#define min THIS IS A NASTY MACRO!
#define max THIS IS A NASTY MACRO!
#include <map>
-#include "test_macros.h"
-
int main(int, char**) {
std::map<int, int> m;
((void)m);
diff --git a/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp b/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp
index 4415c3296c8e0..e0811e02f5c13 100644
--- a/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp
+++ b/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp
@@ -20,10 +20,6 @@
// 1. noexcept and constexpr
// 2. Two closing '>' without a space.
-#ifdef __clang__
-#pragma clang diagnostic ignored "-Wc++11-extensions"
-#endif
-
#include <type_traits>
#include <cassert>
diff --git a/libcxx/test/libcxx/numerics/c.math/undef_min_max.pass.cpp b/libcxx/test/libcxx/numerics/c.math/undef_min_max.pass.cpp
index a9f50171543b9..dc8c9c9d1df4e 100644
--- a/libcxx/test/libcxx/numerics/c.math/undef_min_max.pass.cpp
+++ b/libcxx/test/libcxx/numerics/c.math/undef_min_max.pass.cpp
@@ -5,15 +5,9 @@
//
//===----------------------------------------------------------------------===//
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-W#warnings"
-#endif
-
#define min THIS IS A NASTY MACRO!
#define max THIS IS A NASTY MACRO!
#include <cmath>
-#include "test_macros.h"
-
int main(int, char**) { return 0; }
diff --git a/libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp b/libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
index befd97629e7bc..a62d8a5833567 100644
--- a/libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
+++ b/libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
@@ -12,12 +12,9 @@
// See llvm.org/PR20855
-#ifdef __clang__
-#pragma clang diagnostic ignored "-Wdangling-field"
-#endif
-
#include <tuple>
#include <string>
+
#include "test_macros.h"
template <class Tp>
diff --git a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
index 6adfe63bad113..f8dfd9ad19226 100644
--- a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
+++ b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/assign_tuple_like.pass.cpp
@@ -22,13 +22,6 @@
#include "archetypes.h"
-#include "test_macros.h"
-
-// Clang warns about missing braces when initializing std::array.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wmissing-braces"
-#endif
-
int main(int, char**)
{
using C = TestTypes::TestType;
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
index 6ee26124be357..3eb361a819d58 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
@@ -14,18 +14,15 @@
// constexpr void // constexpr after c++17
// generate_n(Iter first, Size n, Generator gen);
-#include "test_macros.h"
-
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(disable: 4244) // conversion from 'const double' to 'int', possible loss of data
-#endif
-
#include <algorithm>
#include <cassert>
#include "test_iterators.h"
+#include "test_macros.h"
#include "user_defined_integral.h"
+TEST_MSVC_DIAGNOSTIC_IGNORED(4244) // conversion from 'const double' to 'int', possible loss of data
+
struct gen_test
{
TEST_CONSTEXPR int operator()() const {return 2;}
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp
index 868b7d055fa65..bd4dfd8d9238f 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp
@@ -11,13 +11,13 @@
// template <size_t I, class T, size_t N> T& get(array<T, N>& a);
// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Warray-bounds"
-#endif
+// ADDITIONAL_COMPILE_FLAGS: -Wno-array-bounds
#include <array>
#include <cassert>
+#include "test_macros.h"
+
int main(int, char**)
{
{
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
index 21d99c6591990..84bc03816d0b4 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
@@ -10,11 +10,6 @@
// tuple_element<I, array<T, N> >::type
-// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Warray-bounds"
-#endif
-
#include <array>
#include <cassert>
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
index 347ce3e68dbd4..c7702d9f3d166 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
@@ -165,14 +165,10 @@ void test_ctor_with_
diff erent_value_type() {
// Make sure initialization is performed with each element value, not with
// a memory blob.
float array[3] = {0.0f, 1.0f, 2.0f};
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(push)
- #pragma warning(disable: 4244) // conversion from 'float' to 'int', possible loss of data
-#endif // TEST_COMPILER_MSVC
+ TEST_DIAGNOSTIC_PUSH
+ TEST_MSVC_DIAGNOSTIC_IGNORED(4244) // conversion from 'float' to 'int', possible loss of data
std::vector<int> v(array, array + 3);
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(pop)
-#endif // TEST_COMPILER_MSVC
+ TEST_DIAGNOSTIC_POP
assert(v[0] == 0);
assert(v[1] == 1);
assert(v[2] == 2);
diff --git a/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp
index 94a2fc4d2ff9d..f017522b0160b 100644
--- a/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/math_h.pass.cpp
@@ -108,10 +108,9 @@ struct has_abs : decltype(has_abs_imp<T>(0)) {};
void test_abs()
{
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wabsolute-value"
-#endif
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wabsolute-value")
+
static_assert((std::is_same<decltype(abs((float)0)), float>::value), "");
static_assert((std::is_same<decltype(abs((double)0)), double>::value), "");
static_assert(
@@ -132,9 +131,7 @@ void test_abs()
static_assert(!has_abs<unsigned long>::value, "");
static_assert(!has_abs<unsigned long long>::value, "");
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
+ TEST_DIAGNOSTIC_POP
assert(abs(-1.) == 1);
}
diff --git a/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp
index b279d4464f4c9..f8bd7b9afafd5 100644
--- a/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp
@@ -98,10 +98,8 @@
#include <cstdarg>
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic ignored "-Wformat-zero-length"
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // for tmpnam
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
int main(int, char**)
{
@@ -120,7 +118,11 @@ int main(int, char**)
static_assert((std::is_same<decltype(remove("")), int>::value), "");
static_assert((std::is_same<decltype(rename("","")), int>::value), "");
static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), "");
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+ TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
static_assert((std::is_same<decltype(tmpnam(cp)), char*>::value), "");
+ TEST_DIAGNOSTIC_POP
static_assert((std::is_same<decltype(fclose(fp)), int>::value), "");
static_assert((std::is_same<decltype(fflush(fp)), int>::value), "");
static_assert((std::is_same<decltype(fopen("", "")), FILE*>::value), "");
@@ -148,7 +150,11 @@ int main(int, char**)
static_assert((std::is_same<decltype(getc(fp)), int>::value), "");
static_assert((std::is_same<decltype(getchar()), int>::value), "");
#if TEST_STD_VER < 14
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+ TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
static_assert((std::is_same<decltype(gets(cp)), char*>::value), "");
+ TEST_DIAGNOSTIC_POP
#endif
static_assert((std::is_same<decltype(putc(0,fp)), int>::value), "");
static_assert((std::is_same<decltype(putchar(0)), int>::value), "");
diff --git a/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
index 978596b6f589e..9d60f941b6412 100644
--- a/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
@@ -14,12 +14,6 @@
#include "test_macros.h"
-// As of 1/10/2015 clang emits a -Wnonnull warnings even if the warning occurs
-// in an unevaluated context. For this reason we manually suppress the warning.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wnonnull"
-#endif
-
#ifdef abs
#error abs is defined
#endif
@@ -73,10 +67,8 @@ template <class T>
struct has_abs : decltype(has_abs_imp<T>(0)) {};
void test_abs() {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wabsolute-value"
-#endif
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wabsolute-value")
static_assert((std::is_same<decltype(abs((float)0)), float>::value), "");
static_assert((std::is_same<decltype(abs((double)0)), double>::value), "");
static_assert(
@@ -103,9 +95,7 @@ void test_abs() {
static_assert(!has_abs<unsigned long long>::value, "");
static_assert(!has_abs<size_t>::value, "");
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
+ TEST_DIAGNOSTIC_POP
assert(abs(-1.) == 1);
}
diff --git a/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp b/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp
index 2ef6c2291e424..b0b76b5491142 100644
--- a/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp
+++ b/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp
@@ -79,11 +79,7 @@
#include <cstdarg>
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-zero-length"
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
int main(int, char**)
{
@@ -141,14 +137,21 @@ int main(int, char**)
static_assert((std::is_same<decltype(std::remove("")), int>::value), "");
static_assert((std::is_same<decltype(std::rename("","")), int>::value), "");
static_assert((std::is_same<decltype(std::tmpfile()), std::FILE*>::value), "");
+
+ // disable deprecated warnings from the C library
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
static_assert((std::is_same<decltype(std::tmpnam(cp)), char*>::value), "");
+ TEST_DIAGNOSTIC_POP
static_assert((std::is_same<decltype(std::getchar()), int>::value), "");
#if TEST_STD_VER <= 11
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wdeprecated-declarations" // disable the warning from the C library
+ TEST_DIAGNOSTIC_PUSH
+ // disable the warning from the C library
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+ TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
static_assert((std::is_same<decltype(std::gets(cp)), char*>::value), "");
-# pragma GCC diagnostic pop
+ TEST_DIAGNOSTIC_POP
#endif
static_assert((std::is_same<decltype(std::scanf(" ")), int>::value), "");
static_assert((std::is_same<decltype(std::vscanf(" ",va)), int>::value), "");
diff --git a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/move_assign.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/move_assign.pass.cpp
index d29f7b330862a..d0beee1dab4a6 100644
--- a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/move_assign.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/move_assign.pass.cpp
@@ -25,9 +25,7 @@
// The filesystem specification explicitly allows for self-move on
// the directory iterators. Turn off this warning so we can test it.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wself-move"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wself-move")
using namespace fs;
diff --git a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/move_assign.pass.cpp b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/move_assign.pass.cpp
index 03c85f27f608c..abe5dd7e69b3a 100644
--- a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/move_assign.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/move_assign.pass.cpp
@@ -25,9 +25,7 @@
// The filesystem specification explicitly allows for self-move on
// the directory iterators. Turn off this warning so we can test it.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wself-move"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wself-move")
using namespace fs;
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
index 4ecf6289c058a..4664f0f95ea98 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
@@ -196,14 +196,9 @@ Times GetSymlinkTimes(path const& p) {
namespace {
// In some configurations, the comparison is tautological and the test is valid.
-// We disable the warning so that we can actually test it regardless. Also, that
-// diagnostic is pretty new, so also don't fail if old clang does not support it
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunknown-warning-option"
-#pragma clang diagnostic ignored "-Wunknown-pragmas"
-#pragma clang diagnostic ignored "-Wtautological-constant-compare"
-#endif
+// We disable the warning so that we can actually test it regardless.
+TEST_DIAGNOSTIC_PUSH
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-compare")
static const bool SupportsNegativeTimes = [] {
using namespace std::chrono;
@@ -368,9 +363,7 @@ inline bool TimeIsRepresentableByFilesystem(file_time_type tp) {
return true;
}
-#if defined(__clang__)
-#pragma clang diagnostic pop
-#endif
+TEST_DIAGNOSTIC_POP
// Create a sub-second duration using the smallest period the filesystem supports.
file_time_type::duration SubSec(long long val) {
diff --git a/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp b/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
index f95cdc1463af4..ceae8def1edc2 100644
--- a/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
@@ -24,9 +24,7 @@
#include "test_macros.h"
// Ignore warning about std::numeric_limits comparisons being tautological.
-#ifdef __GNUC__
-#pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wtype-limits")
struct short_container {
uint16_t size() const { return 60000; } // not noexcept
diff --git a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp
index 143ccc513c493..4e1a4d63f393c 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp
@@ -18,13 +18,8 @@
#include "test_macros.h"
-#if defined(TEST_COMPILER_CLANG)
-#pragma clang diagnostic ignored "-Wliteral-conversion"
-#endif
-
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(disable: 4244) // conversion from 'X' to 'Y', possible loss of data
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wliteral-conversion")
+TEST_MSVC_DIAGNOSTIC_IGNORED(4244) // conversion from 'X' to 'Y', possible loss of data
int main(int, char**)
{
diff --git a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
index 2900ee2b3262e..c4c8ddd318094 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
@@ -14,12 +14,6 @@
#include "test_macros.h"
-// As of 1/10/2015 clang emits a -Wnonnull warnings even if the warning occurs
-// in an unevaluated context. For this reason we manually suppress the warning.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wnonnull"
-#endif
-
#ifndef EXIT_FAILURE
#error EXIT_FAILURE not defined
#endif
@@ -58,10 +52,8 @@ template <class T>
struct has_abs : decltype(has_abs_imp<T>(0)) {};
void test_abs() {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wabsolute-value"
-#endif
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wabsolute-value")
static_assert((std::is_same<decltype(std::abs((float)0)), float>::value), "");
static_assert((std::is_same<decltype(std::abs((double)0)), double>::value), "");
static_assert(
@@ -88,9 +80,7 @@ void test_abs() {
static_assert(!has_abs<unsigned long long>::value, "");
static_assert(!has_abs<size_t>::value, "");
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
+ TEST_DIAGNOSTIC_POP
assert(std::abs(-1.) == 1);
}
diff --git a/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp b/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
index f59cf2d883c25..768cf6656fe82 100644
--- a/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
+++ b/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
@@ -51,19 +51,15 @@ void test_comparisons()
assert(!(nullptr != p));
}
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnull-conversion"
-#endif
+TEST_DIAGNOSTIC_PUSH
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wnull-conversion")
void test_nullptr_conversions() {
{
bool b(nullptr);
assert(!b);
}
}
-#if defined(__clang__)
-#pragma clang diagnostic pop
-#endif
+TEST_DIAGNOSTIC_POP
int main(int, char**)
diff --git a/libcxx/test/std/library/description/conventions/expos.only.func/synth_three_way.pass.cpp b/libcxx/test/std/library/description/conventions/expos.only.func/synth_three_way.pass.cpp
index 46d92c354250c..d9a6706b3b68b 100644
--- a/libcxx/test/std/library/description/conventions/expos.only.func/synth_three_way.pass.cpp
+++ b/libcxx/test/std/library/description/conventions/expos.only.func/synth_three_way.pass.cpp
@@ -13,11 +13,9 @@
#include "test_macros.h"
-#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#elif defined(TEST_COMPILER_MSVC)
-#pragma warning(disable: 4242 4244) // Various truncation warnings
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_MSVC_DIAGNOSTIC_IGNORED(4242 4244) // Various truncation warnings
#include <cassert>
#include <compare>
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
index 2fa6653c42d3e..5aa2fe6bbbe9f 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_neg_one.pass.cpp
@@ -19,12 +19,11 @@
#include <cassert>
#include <streambuf>
#include <sstream>
+
#include "test_iterators.h"
#include "test_macros.h"
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned
-#endif
+TEST_MSVC_DIAGNOSTIC_IGNORED(4146) // unary minus operator applied to unsigned type, result still unsigned
typedef std::num_get<char, cpp17_input_iterator<const char*> > F;
diff --git a/libcxx/test/std/numerics/c.math/cmath.pass.cpp b/libcxx/test/std/numerics/c.math/cmath.pass.cpp
index b8bf260a0f7c4..c867472662150 100644
--- a/libcxx/test/std/numerics/c.math/cmath.pass.cpp
+++ b/libcxx/test/std/numerics/c.math/cmath.pass.cpp
@@ -113,10 +113,9 @@ void test_abs()
{
// See also "abs.pass.cpp"
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wabsolute-value"
-#endif
+ TEST_DIAGNOSTIC_PUSH
+ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wabsolute-value")
+
static_assert((std::is_same<decltype(std::abs((float)0)), float>::value), "");
static_assert((std::is_same<decltype(std::abs((double)0)), double>::value), "");
static_assert((std::is_same<decltype(std::abs((long double)0)), long double>::value), "");
@@ -135,9 +134,8 @@ void test_abs()
static_assert(!has_abs<unsigned long>::value, "");
static_assert(!has_abs<unsigned long long>::value, "");
static_assert(!has_abs<size_t>::value, "");
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
+
+ TEST_DIAGNOSTIC_POP
assert(std::abs(-1.) == 1);
}
diff --git a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
index 142ea437ddd7d..d9d47c5d8db46 100644
--- a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
@@ -44,10 +44,8 @@ test1()
assert((LCE::min() == (c == 0u ? 1u: 0u)));
#endif
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(push)
- #pragma warning(disable: 4310) // cast truncates constant value
-#endif // TEST_COMPILER_MSVC
+ TEST_DIAGNOSTIC_PUSH
+ TEST_MSVC_DIAGNOSTIC_IGNORED(4310) // cast truncates constant value
#if TEST_STD_VER >= 11
static_assert((LCE::max() == result_type(m - 1u)), "");
@@ -55,9 +53,7 @@ test1()
assert((LCE::max() == result_type(m - 1u)));
#endif
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(pop)
-#endif // TEST_COMPILER_MSVC
+ TEST_DIAGNOSTIC_POP
static_assert((LCE::default_seed == 1), "");
where(LCE::multiplier);
diff --git a/libcxx/test/std/ranges/range.factories/range.iota.view/ctor.value.bound.pass.cpp b/libcxx/test/std/ranges/range.factories/range.iota.view/ctor.value.bound.pass.cpp
index 68dc0a2902aa6..bed35548546cc 100644
--- a/libcxx/test/std/ranges/range.factories/range.iota.view/ctor.value.bound.pass.cpp
+++ b/libcxx/test/std/ranges/range.factories/range.iota.view/ctor.value.bound.pass.cpp
@@ -11,11 +11,9 @@
#include "test_macros.h"
-#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#elif defined(TEST_COMPILER_MSVC)
-#pragma warning(disable: 4018 4389) // various "signed/unsigned mismatch"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_MSVC_DIAGNOSTIC_IGNORED(4018 4389) // various "signed/unsigned mismatch"
// constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
diff --git a/libcxx/test/std/ranges/range.factories/range.iota.view/end.pass.cpp b/libcxx/test/std/ranges/range.factories/range.iota.view/end.pass.cpp
index 48eae501b8c80..5b008e08d2ce8 100644
--- a/libcxx/test/std/ranges/range.factories/range.iota.view/end.pass.cpp
+++ b/libcxx/test/std/ranges/range.factories/range.iota.view/end.pass.cpp
@@ -11,11 +11,9 @@
#include "test_macros.h"
-#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#elif defined(TEST_COMPILER_MSVC)
-#pragma warning(disable: 4018 4389) // various "signed/unsigned mismatch"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_MSVC_DIAGNOSTIC_IGNORED(4018 4389) // various "signed/unsigned mismatch"
// constexpr auto end() const;
// constexpr iterator end() const requires same_as<W, Bound>;
diff --git a/libcxx/test/std/ranges/range.factories/range.iota.view/iterator/star.pass.cpp b/libcxx/test/std/ranges/range.factories/range.iota.view/iterator/star.pass.cpp
index a8358c53a9698..1731aa14f1e14 100644
--- a/libcxx/test/std/ranges/range.factories/range.iota.view/iterator/star.pass.cpp
+++ b/libcxx/test/std/ranges/range.factories/range.iota.view/iterator/star.pass.cpp
@@ -13,11 +13,9 @@
#include "test_macros.h"
-#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#elif defined(TEST_COMPILER_MSVC)
-#pragma warning(disable: 4018) // various "signed/unsigned mismatch"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_MSVC_DIAGNOSTIC_IGNORED(4018) // various "signed/unsigned mismatch"
#include <ranges>
#include <cassert>
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/noncopyable_return_type.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/noncopyable_return_type.pass.cpp
index d5753a9e22e95..911edc10e1e17 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/noncopyable_return_type.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/noncopyable_return_type.pass.cpp
@@ -24,9 +24,8 @@
#include "test_macros.h"
// Prevent warning on the `const NonCopyable()` function type.
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic ignored "-Wignored-qualifiers"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wignored-qualifiers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wignored-qualifiers")
struct NonCopyable {
NonCopyable() = default;
diff --git a/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp b/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp
index e7453c81cf77e..832fda32975c2 100644
--- a/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp
@@ -25,19 +25,13 @@
// Disable the tautological constant evaluation warnings for this test,
// because it's explicitly testing those cases.
-#if TEST_HAS_WARNING("-Wconstant-evaluated") && defined(__clang__)
-#pragma clang diagnostic ignored "-Wconstant-evaluated"
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wconstant-evaluated")
+TEST_MSVC_DIAGNOSTIC_IGNORED(5063)
template <bool> struct InTemplate {};
int main(int, char**)
{
-#ifdef __cpp_lib_is_constant_evaluated
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(push)
- #pragma warning(disable: 5063) // 'std::is_constant_evaluated' always evaluates to true in manifestly constant-evaluated expressions
-#endif // TEST_COMPILER_MSVC
// Test the signature
{
ASSERT_SAME_TYPE(decltype(std::is_constant_evaluated()), bool);
@@ -55,9 +49,5 @@ int main(int, char**)
static int local_static = std::is_constant_evaluated() ? 42 : -1;
assert(local_static == 42);
}
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(pop)
-#endif // TEST_COMPILER_MSVC
-#endif // __cpp_lib_is_constant_evaluated
return 0;
}
diff --git a/libcxx/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp b/libcxx/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp
index dcd9cdad172ff..28495cfebd45c 100644
--- a/libcxx/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp
@@ -8,6 +8,8 @@
// UNSUPPORTED: c++03
+// ADDITIONAL_COMPILE_FLAGS: -D _LIBCPP_USE_IS_CONVERTIBLE_FALLBACK
+
// type_traits
// is_convertible
@@ -18,11 +20,8 @@
// `__is_convertible` with the same name when clang doesn't.
// Because this test forces the use of the fallback even when clang provides
// it causing a keyword incompatibility.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wkeyword-compat"
-#endif
-
-#define _LIBCPP_USE_IS_CONVERTIBLE_FALLBACK
-#include "is_convertible.pass.cpp"
#include "test_macros.h"
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wkeyword-compat")
+
+#include "is_convertible.pass.cpp"
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp
index 1a32efa427209..87abf3268fa9d 100644
--- a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp
@@ -10,11 +10,6 @@
// is_destructible
-// Prevent warning when testing the Abstract test type.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wdelete-non-virtual-dtor"
-#endif
-
#include <type_traits>
#include "test_macros.h"
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp
index 853f32f80fe32..60d55620f32a4 100644
--- a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp
@@ -10,11 +10,6 @@
// is_nothrow_destructible
-// Prevent warning when testing the Abstract test type.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wdelete-non-virtual-dtor"
-#endif
-
#include <type_traits>
#include "test_macros.h"
diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
index 3fc1d83742204..af1361c3f0e78 100644
--- a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
@@ -10,11 +10,6 @@
// is_trivially_destructible
-// Prevent warning when testing the Abstract test type.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wdelete-non-virtual-dtor"
-#endif
-
#include <type_traits>
#include "test_macros.h"
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
index d9b2dbf8a017a..4d0c962019895 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
+++ b/libcxx/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
@@ -18,9 +18,7 @@
#include "test_macros.h"
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
-#endif
+TEST_MSVC_DIAGNOSTIC_IGNORED(6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
template <std::size_t N>
void test_char_pointer_ctor()
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
index 6526be4e16bc2..b4de74b00422b 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
+++ b/libcxx/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
@@ -15,9 +15,7 @@
#include "test_macros.h"
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
-#endif
+TEST_MSVC_DIAGNOSTIC_IGNORED(6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
template <std::size_t N>
void test_val_ctor()
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
index b2fbd82793b3a..cdf52f72c4f22 100644
--- a/libcxx/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
+++ b/libcxx/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
@@ -16,9 +16,7 @@
#include "../bitset_test_cases.h"
#include "test_macros.h"
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
-#endif
+TEST_MSVC_DIAGNOSTIC_IGNORED(6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
template <std::size_t N>
void test_reset_one() {
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/three_way.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/three_way.pass.cpp
index 5c5876cce30d8..d954314874c4f 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/three_way.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/three_way.pass.cpp
@@ -18,11 +18,9 @@
#include "test_macros.h"
-#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#elif defined(TEST_COMPILER_MSVC)
-#pragma warning(disable: 4242 4244) // Various truncation warnings
-#endif
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_MSVC_DIAGNOSTIC_IGNORED(4242 4244)
#include <cassert>
#include <compare>
diff --git a/libcxx/test/support/charconv_test_helpers.h b/libcxx/test/support/charconv_test_helpers.h
index fe0e68bf7f83a..32a8d48b4bfd3 100644
--- a/libcxx/test/support/charconv_test_helpers.h
+++ b/libcxx/test/support/charconv_test_helpers.h
@@ -180,10 +180,9 @@ struct roundtrip_test_base
r2 = from_chars(buf, r.ptr, x, args...);
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(push)
- #pragma warning(disable: 4127) // conditional expression is constant
-#endif // TEST_COMPILER_MSVC
+ TEST_DIAGNOSTIC_PUSH
+ TEST_MSVC_DIAGNOSTIC_IGNORED(4127) // conditional expression is constant
+
if (std::is_signed<T>::value && v < 0 && std::is_unsigned<X>::value)
{
assert(x == 0xc);
@@ -196,9 +195,8 @@ struct roundtrip_test_base
assert(r2.ptr == r.ptr);
assert(r2.ec == std::errc::result_out_of_range);
}
-#ifdef TEST_COMPILER_MSVC
- #pragma warning(pop)
-#endif // TEST_COMPILER_MSVC
+
+ TEST_DIAGNOSTIC_POP
}
}
diff --git a/libcxx/test/support/count_new.h b/libcxx/test/support/count_new.h
index 2d0f3f686fea9..18b0c5609d7c8 100644
--- a/libcxx/test/support/count_new.h
+++ b/libcxx/test/support/count_new.h
@@ -347,17 +347,13 @@ class MemCounter
const bool MemCounter::disable_checking = false;
#endif
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(push)
-#pragma warning(disable: 4640) // '%s' construction of local static object is not thread safe (/Zc:threadSafeInit-)
-#endif // TEST_COMPILER_MSVC
+TEST_DIAGNOSTIC_PUSH
+TEST_MSVC_DIAGNOSTIC_IGNORED(4640) // '%s' construction of local static object is not thread safe (/Zc:threadSafeInit-)
inline MemCounter* getGlobalMemCounter() {
static MemCounter counter((MemCounter::MemCounterCtorArg_()));
return &counter;
}
-#ifdef TEST_COMPILER_MSVC
-#pragma warning(pop)
-#endif
+TEST_DIAGNOSTIC_POP
MemCounter &globalMemCounter = *getGlobalMemCounter();
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index 0ac4867c89829..08d3865b67ffd 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -23,11 +23,6 @@
#include <ciso646>
#endif
-#if defined(__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wvariadic-macros"
-#endif
-
#define TEST_STRINGIZE_IMPL(x) #x
#define TEST_STRINGIZE(x) TEST_STRINGIZE_IMPL(x)
@@ -398,8 +393,30 @@ inline void DoNotOptimize(Tp const& value) {
# define TEST_HAS_NO_INCOMPLETE_RANGES
#endif
-#if defined(__GNUC__)
-#pragma GCC diagnostic pop
+#if defined(TEST_COMPILER_CLANG)
+# define TEST_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
+# define TEST_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
+# define TEST_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(TEST_STRINGIZE(clang diagnostic ignored str))
+# define TEST_GCC_DIAGNOSTIC_IGNORED(str)
+# define TEST_MSVC_DIAGNOSTIC_IGNORED(num)
+#elif defined(TEST_COMPILER_GCC)
+# define TEST_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
+# define TEST_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
+# define TEST_CLANG_DIAGNOSTIC_IGNORED(str)
+# define TEST_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(TEST_STRINGIZE(GCC diagnostic ignored str))
+# define TEST_MSVC_DIAGNOSTIC_IGNORED(num)
+#elif defined(TEST_COMPILER_MSVC)
+# define TEST_DIAGNOSTIC_PUSH _Pragma("warning(push)")
+# define TEST_DIAGNOSTIC_POP _Pragma("warning(pop)")
+# define TEST_CLANG_DIAGNOSTIC_IGNORED(str)
+# define TEST_GCC_DIAGNOSTIC_IGNORED(str)
+# define TEST_MSVC_DIAGNOSTIC_IGNORED(num) _Pragma(TEST_STRINGIZE(warning(disable: num)))
+#else
+# define TEST_DIAGNOSTIC_PUSH
+# define TEST_DIAGNOSTIC_POP
+# define TEST_CLANG_DIAGNOSTIC_IGNORED(str)
+# define TEST_GCC_DIAGNOSTIC_IGNORED(str)
+# define TEST_MSVC_DIAGNOSTIC_IGNORED(num)
#endif
#endif // SUPPORT_TEST_MACROS_HPP
diff --git a/libcxx/test/support/unique_ptr_test_helper.h b/libcxx/test/support/unique_ptr_test_helper.h
index 1613ad197457e..83c41a4c93937 100644
--- a/libcxx/test/support/unique_ptr_test_helper.h
+++ b/libcxx/test/support/unique_ptr_test_helper.h
@@ -134,11 +134,6 @@ void doIncompleteTypeTest(int expect_alive, Args&&... ctor_args) {
StoresIncomplete<IncompleteT, Del>::~StoresIncomplete() {}
#
-#if defined(__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wvariadic-macros"
-#endif
-
#if TEST_STD_VER >= 11
#define DEFINE_AND_RUN_IS_INCOMPLETE_TEST(...) \
static int is_incomplete_test() { __VA_ARGS__ return 0; } \
@@ -149,8 +144,4 @@ void doIncompleteTypeTest(int expect_alive, Args&&... ctor_args) {
INCOMPLETE_TEST_EPILOGUE()
#endif
-#if defined(__GNUC__)
-#pragma GCC diagnostic pop
-#endif
-
#endif // TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H
More information about the libcxx-commits
mailing list