diff --git a/libcxx/src/filesystem/filesystem_common.h b/libcxx/src/filesystem/filesystem_common.h --- 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 -#endif - -#if !defined(_LIBCPP_WIN32API) +#else # include // for DIR & friends # include /* values for fchmodat */ # include # include # include // for ::utimes as used in __last_write_time # include -#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 @@ _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 --- 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 -#include "test_macros.h" - int main(int, char**) { std::map m; ((void)m); diff --git a/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp b/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp --- a/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp +++ b/libcxx/test/libcxx/minimal_cxx11_configuration.pass.cpp @@ -20,13 +20,13 @@ // 1. noexcept and constexpr // 2. Two closing '>' without a space. -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wc++11-extensions" -#endif - #include #include +#include "test_macros.h" + +TEST_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") + // Equals delete and default are allowed in minimal C++03 mode. namespace test_eq_delete_and_default { void t1() = delete; 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 --- 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 -#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 --- 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 #include + #include "test_macros.h" template 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 --- 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 --- 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 #include #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 --- a/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp @@ -10,11 +10,6 @@ // template T& get(array& a); -// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify. -#if defined(__clang__) -#pragma clang diagnostic ignored "-Warray-bounds" -#endif - #include #include 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 --- 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 >::type -// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify. -#if defined(__clang__) -#pragma clang diagnostic ignored "-Warray-bounds" -#endif - #include #include 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 --- 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 @@ // 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 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 --- 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 @@ 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::value), ""); static_assert((std::is_same::value), ""); static_assert( @@ -132,9 +131,7 @@ static_assert(!has_abs::value, ""); static_assert(!has_abs::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 --- 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 -#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**) { 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 --- 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 @@ struct has_abs : decltype(has_abs_imp(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::value), ""); static_assert((std::is_same::value), ""); static_assert( @@ -103,9 +95,7 @@ static_assert(!has_abs::value, ""); static_assert(!has_abs::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 --- 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 -#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**) { @@ -145,10 +141,12 @@ static_assert((std::is_same::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::value), ""); -# pragma GCC diagnostic pop + TEST_DIAGNOSTIC_POP #endif static_assert((std::is_same::value), ""); static_assert((std::is_same::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 --- 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 --- 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 --- 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 @@ 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 @@ 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 --- 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 --- 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 --- 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 @@ struct has_abs : decltype(has_abs_imp(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::value), ""); static_assert((std::is_same::value), ""); static_assert( @@ -88,9 +80,7 @@ static_assert(!has_abs::value, ""); static_assert(!has_abs::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 --- 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 @@ 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 --- 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 #include 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 --- 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 #include #include + #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 > F; diff --git a/libcxx/test/std/numerics/c.math/cmath.pass.cpp b/libcxx/test/std/numerics/c.math/cmath.pass.cpp --- a/libcxx/test/std/numerics/c.math/cmath.pass.cpp +++ b/libcxx/test/std/numerics/c.math/cmath.pass.cpp @@ -113,10 +113,9 @@ { // 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::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); @@ -135,9 +134,8 @@ static_assert(!has_abs::value, ""); static_assert(!has_abs::value, ""); static_assert(!has_abs::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 --- 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 @@ 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 @@ 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 --- 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 @@ -12,11 +12,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 value, type_identity_t 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 --- 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 @@ -12,11 +12,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; 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 --- 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 @@ -14,11 +14,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 #include 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 --- 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 --- 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 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 @@ 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 --- 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 @@ -18,9 +18,6 @@ // `__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" 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 --- 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 #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 --- 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 #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 --- 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 #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 --- 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 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 --- 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 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 --- 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 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 --- 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 #include diff --git a/libcxx/test/support/charconv_test_helpers.h b/libcxx/test/support/charconv_test_helpers.h --- a/libcxx/test/support/charconv_test_helpers.h +++ b/libcxx/test/support/charconv_test_helpers.h @@ -180,10 +180,9 @@ 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::value && v < 0 && std::is_unsigned::value) { assert(x == 0xc); @@ -196,9 +195,8 @@ 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 --- a/libcxx/test/support/count_new.h +++ b/libcxx/test/support/count_new.h @@ -347,17 +347,13 @@ 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 --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -23,11 +23,6 @@ #include #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) @@ -394,8 +389,30 @@ # define TEST_HAS_NO_FGETPOS_FSETPOS #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 --- a/libcxx/test/support/unique_ptr_test_helper.h +++ b/libcxx/test/support/unique_ptr_test_helper.h @@ -134,11 +134,6 @@ StoresIncomplete::~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 @@ INCOMPLETE_TEST_EPILOGUE() #endif -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - #endif // TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H