[libcxx-commits] [libcxx] [libc++][test] Use `TEST_MEOW_DIAGNOSTIC_IGNORED` instead of `ADDITIONAL_COMPILE_FLAGS` (PR #75133)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 11 19:43:10 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

<details>
<summary>Changes</summary>

Found while running libc++'s tests with MSVC's STL.

This is an alternative to my original PR #<!-- -->74974. @<!-- -->cpplearner suggested in https://github.com/llvm/llvm-project/pull/74974#issuecomment-1848928855 that we should follow the precedent of using these macros:

https://github.com/llvm/llvm-project/blob/59f3661bd22766e5d0dea391d4950605b249594a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/three_way.pass.cpp#L19-L23

This PR does so throughout `libcxx/test/std`, converting existing Clang/GCC warning suppressions, and adding MSVC warning suppressions. (As usual, I'm not tooled up to work on `libcxx/test/libcxx`, so a followup PR should change that subdirectory if desired.)

Additional notes:

* Most suppressions are for the entire test, especially when test code triggers warnings in STL algorithms. This is why the usual pattern is to add or move `#include "test_macros.h"` to the top of the test, then ignore diagnostics. However, in a few cases, the MSVC warnings are very specific and I can locally suppress them with push/disable/pop.

* In `test_macros.h`, I'm adding `TEST_MEOW_DIAGNOSTIC_ERROR` for `libcxx/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp` to use someday. (Note that `clang diagnostic error` is intentional;






---

Patch is 39.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75133.diff


36 Files Affected:

- (modified) libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/ranges.replace.pass.cpp (+5) 
- (modified) libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp (+14-2) 
- (modified) libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp (+7-3) 
- (modified) libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp (+8-2) 
- (modified) libcxx/test/std/atomics/atomics.types.generic/general.compile.pass.cpp (+6) 
- (modified) libcxx/test/std/atomics/atomics.types.generic/pointer.compile.pass.cpp (+8) 
- (modified) libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp (+7-6) 
- (modified) libcxx/test/std/containers/associative/map/map.modifiers/insert_range.pass.cpp (+6-3) 
- (modified) libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_range.pass.cpp (+6-4) 
- (modified) libcxx/test/std/containers/associative/multiset/insert_range.pass.cpp (+6-3) 
- (modified) libcxx/test/std/containers/associative/set/insert_range.pass.cpp (+6-3) 
- (modified) libcxx/test/std/containers/sequences/array/array.tuple/get.verify.cpp (+4-1) 
- (modified) libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp (+6-3) 
- (modified) libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp (+6-4) 
- (modified) libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp (+6-4) 
- (modified) libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp (+6-3) 
- (modified) libcxx/test/std/containers/views/mdspan/layout_stride/deduction.pass.cpp (+5-3) 
- (modified) libcxx/test/std/containers/views/mdspan/mdspan/conversion.pass.cpp (+5-2) 
- (modified) libcxx/test/std/depr/depr.c.headers/setjmp_h.compile.pass.cpp (+5-2) 
- (modified) libcxx/test/std/depr/depr.numeric.limits.has.denorm/deprecated.verify.cpp (+4-1) 
- (modified) libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/buffered_reads.pass.cpp (+6-1) 
- (modified) libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/buffered_writes.pass.cpp (+6-1) 
- (modified) libcxx/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp (+6-6) 
- (modified) libcxx/test/std/language.support/support.runtime/csetjmp.pass.cpp (+5) 
- (modified) libcxx/test/std/ranges/range.adaptors/range.lazy.split/constraints.compile.pass.cpp (+6) 
- (modified) libcxx/test/std/ranges/range.utility/range.utility.conv/to.pass.cpp (+5-1) 
- (modified) libcxx/test/std/strings/basic.string/string.cons/from_range_deduction.pass.cpp (+6-2) 
- (modified) libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit_lwg3343.pass.cpp (+6) 
- (modified) libcxx/test/std/thread/thread.jthread/assign.move.pass.cpp (+5-2) 
- (modified) libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp (+4-8) 
- (modified) libcxx/test/std/utilities/meta/meta.unary/dependent_return_type.compile.pass.cpp (+6-3) 
- (modified) libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp (+6-4) 
- (modified) libcxx/test/std/utilities/variant/variant.variant/implicit_ctad.pass.cpp (+5-4) 
- (modified) libcxx/test/support/msvc_stdlib_force_include.h (-10) 
- (modified) libcxx/test/support/test_macros.h (+8) 
- (modified) libcxx/utils/libcxx/test/features.py (+4-2) 


``````````diff
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/ranges.replace.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/ranges.replace.pass.cpp
index ab2f705bafe9d0..31468cc4c13dff 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/ranges.replace.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/ranges.replace.pass.cpp
@@ -21,6 +21,11 @@
 //   constexpr borrowed_iterator_t<R>
 //     ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
 
+#include "test_macros.h"
+
+// MSVC warning C4244: 'argument': conversion from 'const _Ty2' to 'T', possible loss of data
+TEST_MSVC_DIAGNOSTIC_IGNORED(4244)
+
 #include <algorithm>
 #include <array>
 #include <cassert>
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
index e28cbe2a08de4a..1f9cb9b9cee5a7 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
@@ -18,15 +18,21 @@
 //   constexpr bool     // constexpr after c++17
 //   equal(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
 
+#include "test_macros.h"
+
 // We test the cartesian product, so we sometimes compare differently signed types
-// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+// MSVC warning C4242: 'argument': conversion from 'int' to 'const _Ty', possible loss of data
+// MSVC warning C4244: 'argument': conversion from 'wchar_t' to 'const _Ty', possible loss of data
+// MSVC warning C4389: '==': signed/unsigned mismatch
+TEST_MSVC_DIAGNOSTIC_IGNORED(4242 4244 4389)
 
 #include <algorithm>
 #include <cassert>
 #include <functional>
 
 #include "test_iterators.h"
-#include "test_macros.h"
 #include "type_algorithms.h"
 
 template <class UnderlyingType, class Iter1>
@@ -58,6 +64,10 @@ struct Test {
 struct TestNarrowingEqualTo {
   template <class UnderlyingType>
   TEST_CONSTEXPR_CXX20 void operator()() {
+  TEST_DIAGNOSTIC_PUSH
+  // MSVC warning C4310: cast truncates constant value
+  TEST_MSVC_DIAGNOSTIC_IGNORED(4310)
+
     UnderlyingType a[] = {
         UnderlyingType(0x1000),
         UnderlyingType(0x1001),
@@ -71,6 +81,8 @@ struct TestNarrowingEqualTo {
         UnderlyingType(0x1603),
         UnderlyingType(0x1604)};
 
+  TEST_DIAGNOSTIC_POP
+
     assert(std::equal(a, a + 5, b, std::equal_to<char>()));
 #if TEST_STD_VER >= 14
     assert(std::equal(a, a + 5, b, b + 5, std::equal_to<char>()));
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
index b55a852c10cafa..be65683c373699 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
-
 // <algorithm>
 
 // template<InputIterator Iter, class T>
@@ -15,12 +13,18 @@
 //   constexpr Iter   // constexpr after C++17
 //   find(Iter first, Iter last, const T& value);
 
+#include "test_macros.h"
+
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+// MSVC warning C4389: '==': signed/unsigned mismatch
+TEST_MSVC_DIAGNOSTIC_IGNORED(4389)
+
 #include <algorithm>
 #include <cassert>
 #include <vector>
 #include <type_traits>
 
-#include "test_macros.h"
 #include "test_iterators.h"
 #include "type_algorithms.h"
 
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
index 22f938f73ae078..994fb3daf6b980 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
@@ -10,8 +10,6 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
-// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
-
 // template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
 //   requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
 //   constexpr I ranges::find(I first, S last, const T& value, Proj proj = {});
@@ -20,6 +18,14 @@
 //   constexpr borrowed_iterator_t<R>
 //     ranges::find(R&& r, const T& value, Proj proj = {});
 
+#include "test_macros.h"
+
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
+// MSVC warning C4242: 'argument': conversion from 'const _Ty' to 'ElementT', possible loss of data
+// MSVC warning C4244: 'argument': conversion from 'const _Ty' to 'ElementT', possible loss of data
+TEST_MSVC_DIAGNOSTIC_IGNORED(4242 4244)
+
 #include <algorithm>
 #include <array>
 #include <cassert>
diff --git a/libcxx/test/std/atomics/atomics.types.generic/general.compile.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/general.compile.pass.cpp
index 9f2a28256184ce..fead6e2e5f6c2c 100644
--- a/libcxx/test/std/atomics/atomics.types.generic/general.compile.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.generic/general.compile.pass.cpp
@@ -74,9 +74,15 @@ void test() {
 
   TEST_IGNORE_NODISCARD a.is_lock_free();
 
+  TEST_DIAGNOSTIC_PUSH
+  // MSVC warning C4197: 'volatile std::atomic<operator_hijacker>': top-level volatile in cast is ignored
+  TEST_MSVC_DIAGNOSTIC_IGNORED(4197)
+
   TEST_IGNORE_NODISCARD T();
   TEST_IGNORE_NODISCARD T(v);
 
+  TEST_DIAGNOSTIC_POP
+
   TEST_IGNORE_NODISCARD a.load();
   TEST_IGNORE_NODISCARD static_cast<typename T::value_type>(a);
   a.store(v);
diff --git a/libcxx/test/std/atomics/atomics.types.generic/pointer.compile.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/pointer.compile.pass.cpp
index 9049beaa9c7897..961aed3b4fb1a9 100644
--- a/libcxx/test/std/atomics/atomics.types.generic/pointer.compile.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.generic/pointer.compile.pass.cpp
@@ -98,8 +98,16 @@ void test() {
 
   a.store(v);
   a = v;
+
+  TEST_DIAGNOSTIC_PUSH
+  // MSVC warning C4197: 'volatile std::atomic<operator_hijacker *>': top-level volatile in cast is ignored
+  TEST_MSVC_DIAGNOSTIC_IGNORED(4197)
+
   TEST_IGNORE_NODISCARD T();
   TEST_IGNORE_NODISCARD T(v);
+
+  TEST_DIAGNOSTIC_POP
+
   TEST_IGNORE_NODISCARD a.load();
   TEST_IGNORE_NODISCARD static_cast<typename T::value_type>(a);
   TEST_IGNORE_NODISCARD* a;
diff --git a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
index 4921a48bcccc17..152978166ccfcf 100644
--- a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
+++ b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
@@ -8,15 +8,18 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
-// We voluntarily use std::default_initializable on types that have redundant
-// or ignored cv-qualifiers -- don't warn about it.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-ignored-qualifiers
-
 // template<class T>
 //     concept default_initializable = constructible_from<T> &&
 //     requires { T{}; } &&
 //     is-default-initializable<T>;
 
+#include "test_macros.h"
+
+// We voluntarily use std::default_initializable on types that have redundant
+// or ignored cv-qualifiers -- don't warn about it.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wignored-qualifiers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wignored-qualifiers")
+
 #include <array>
 #include <concepts>
 #include <deque>
@@ -34,8 +37,6 @@
 #include <unordered_set>
 #include <vector>
 
-#include "test_macros.h"
-
 struct Empty {};
 
 struct CtorDefaulted {
diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_range.pass.cpp
index 1d7fe7193facf4..00be60d15d4528 100644
--- a/libcxx/test/std/containers/associative/map/map.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <map>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <map>
 
 #include "../../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   // Note: we want to use a pair with non-const elements for input (an assignable type is a lot more convenient) but
diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_range.pass.cpp
index c7c05a896bc9f9..4d289ffeefb4af 100644
--- a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <map>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <map>
 
 #include "../../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   // Note: we want to use a pair with non-const elements for input (an assignable type is a lot more convenient) but
@@ -38,4 +41,3 @@ int main(int, char**) {
 
   return 0;
 }
-
diff --git a/libcxx/test/std/containers/associative/multiset/insert_range.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_range.pass.cpp
index 9dd85eea47c290..fbe0097292ed9a 100644
--- a/libcxx/test/std/containers/associative/multiset/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/associative/multiset/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <set>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <set>
 
 #include "../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
diff --git a/libcxx/test/std/containers/associative/set/insert_range.pass.cpp b/libcxx/test/std/containers/associative/set/insert_range.pass.cpp
index 1956fc6bd7f3ea..bf51f5366af941 100644
--- a/libcxx/test/std/containers/associative/set/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/associative/set/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <set>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <set>
 
 #include "../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.verify.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.verify.cpp
index 9052b4359f6b0a..d96b23082ef4fb 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get.verify.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.verify.cpp
@@ -10,8 +10,11 @@
 
 // template <size_t I, class T, size_t N> T& get(array<T, N>& a);
 
+#include "test_macros.h"
+
 // Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-array-bounds
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Warray-bounds")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Warray-bounds")
 
 #include <array>
 #include <cassert>
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp
index 8b004336f68cde..a482a57168a4fd 100644
--- a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <unordered_map>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <unordered_map>
 
 #include "../../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   // Note: we want to use a pair with non-const elements for input (an assignable type is a lot more convenient) but
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp
index fcde119f487030..8de0bb28e9b840 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <unordered_map>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <unordered_map>
 
 #include "../../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   // Note: we want to use a pair with non-const elements for input (an assignable type is a lot more convenient) but
@@ -38,4 +41,3 @@ int main(int, char**) {
 
   return 0;
 }
-
diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp
index 73ac4cf071e1bb..5444eeaad57319 100644
--- a/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <set>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <unordered_set>
 
 #include "../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
@@ -34,4 +37,3 @@ int main(int, char**) {
 
   return 0;
 }
-
diff --git a/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp
index c6306a28b7adb5..c8c7be2d69073e 100644
--- a/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp
@@ -7,18 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
-// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
 
 // <set>
 
 // template<container-compatible-range<value_type> R>
 //   void insert_range(R&& rg); // C++23
 
+#include "test_macros.h"
+
+// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
+
 #include <unordered_set>
 
 #include "../../insert_range_maps_sets.h"
-#include "test_macros.h"
 
 int main(int, char**) {
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
diff --git a/libcxx/test/std/containers/views/mdspan/layout_stride/deduction.pass.cpp b/libcxx/test/std/containers/views/mdspan/layout_stride/deduction.pass.cpp
index 0e0a079b598bc0..a7a6cf693bb69d 100644
--- a/libcxx/test/std/containers/views/mdspan/layout_stride/deduction.pass.cpp
+++ b/libcxx/test/std/containers/views/mdspan/layout_stride/deduction.pass.cpp
@@ -6,17 +6,19 @@
 //
 //===----------------------------------------------------------------------===//
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
-// ADDITIONAL_COMPILE_FLAGS: -Wno-ctad-maybe-unsupported
 
 // <mdspan>
 
+#include "test_macros.h"
+
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wctad-maybe-unsupported")
+TEST_GCC_DIAGNOSTIC_IGNORED("-Wctad-maybe-unsupported")
+
 #include <mdspan>
 #include <type_traits>
 #include <concepts>
 #include <cassert>
 
-#include "test_macros.h"
-
 // mdspan
 
 // layout_stride::mapping does not h...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/75133


More information about the libcxx-commits mailing list