[libcxx-commits] [libcxx] [libc++] Fix the enable_warnings=True|False Lit parameter (PR #214113)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 4 18:48:21 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

<details>
<summary>Changes</summary>

Our enable_warnings=False parameter in the test suite was basically not working as intended. Instead of disabling warnings, it would disable all warning-related flags, including flags that are required for the test suite to pass (e.g. -Wno-user-defined-literals). As a result, it couldn't be turned off.

This patch splits the warning flags into two sets, one which contains things like -Wno-user-defined-literals and is always enabled, and one which contains the actual warning flags (e.g. -Wall) and which is only enabled when `--param enable_warnings=True` is passed.

---
Full diff: https://github.com/llvm/llvm-project/pull/214113.diff


4 Files Affected:

- (modified) libcxx/test/libcxx/diagnostics/unused_variables.verify.cpp (+3) 
- (modified) libcxx/test/selftest/pass.cpp/werror.pass.cpp (+3) 
- (modified) libcxx/test/selftest/sh.cpp/werror.sh.cpp (+3) 
- (modified) libcxx/utils/libcxx/test/params.py (+38-17) 


``````````diff
diff --git a/libcxx/test/libcxx/diagnostics/unused_variables.verify.cpp b/libcxx/test/libcxx/diagnostics/unused_variables.verify.cpp
index c36e32d67e37f..b3631f8700c77 100644
--- a/libcxx/test/libcxx/diagnostics/unused_variables.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/unused_variables.verify.cpp
@@ -8,6 +8,9 @@
 
 // Make sure that we warn on unused variables of libc++ classes which behave like value types.
 
+// The test suite doesn't necessarily enable that warning, so make sure we always do.
+// ADDITIONAL_COMPILE_FLAGS: -Wunused-variable
+
 #include <deque>
 #include <forward_list>
 #include <list>
diff --git a/libcxx/test/selftest/pass.cpp/werror.pass.cpp b/libcxx/test/selftest/pass.cpp/werror.pass.cpp
index 590785fc1774d..f789966f98631 100644
--- a/libcxx/test/selftest/pass.cpp/werror.pass.cpp
+++ b/libcxx/test/selftest/pass.cpp/werror.pass.cpp
@@ -17,6 +17,9 @@
 // TODO: We don't enable -Werror on GCC right now, because too many tests fail.
 // UNSUPPORTED: gcc
 
+// This test only makes sense when the test suite is run with warnings enabled.
+// UNSUPPORTED: !enable-warnings
+
 int main(int, char**) {
     int foo;
 }
diff --git a/libcxx/test/selftest/sh.cpp/werror.sh.cpp b/libcxx/test/selftest/sh.cpp/werror.sh.cpp
index 3188f57ec8fd1..b5d445ac10018 100644
--- a/libcxx/test/selftest/sh.cpp/werror.sh.cpp
+++ b/libcxx/test/selftest/sh.cpp/werror.sh.cpp
@@ -14,6 +14,9 @@
 // TODO: We don't enable -Werror on GCC right now, because too many tests fail.
 // UNSUPPORTED: gcc
 
+// This test only makes sense when the test suite is run with warnings enabled.
+// UNSUPPORTED: !enable-warnings
+
 // RUN: %{build} -Wunused-variable
 // RUN: %{run}
 
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index d0bb38ab84df4..476a4c6aabae6 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -14,7 +14,9 @@
 from libcxx.test.features.compiler import _isClang, _isAppleClang, _isGCC, _isMSVC
 
 
-_warningFlags = [
+# Warnings that we enable when running the test suite with warnings enabled, which is
+# controlled by `--param enable_warnings=True|False`.
+_enabledWarningFlags = [
     "-Werror",
     "-Wall",
     "-Wctad-maybe-unsupported",
@@ -22,23 +24,49 @@
     "-Wshadow",
     "-Wundef",
     "-Wunused-template",
+    '-Wdeprecated-copy',
+    '-Wdeprecated-copy-dtor',
+    "-Wshift-negative-value",
+
+    # These warnings should be enabled in order to support the MSVC
+    # team using the test suite; They enable the warnings below and
+    # expect the test suite to be clean.
+    "-Wsign-compare",
+    "-Wunused-variable",
+    "-Wunused-parameter",
+    "-Wunreachable-code",
+
+    # Technically not a warning flag, but might as well be:
+    "-flax-vector-conversions=none",
+]
+
+# Warnings that we always disable when running the test suite. Some of these are warnings that
+# are enabled by default by the compiler, and others would be enabled by the flags above.
+#
+# Since the last warning flag on the command line wins, it is important that these flags be
+# added after the flags above.
+_silencedWarningFlags = [
+    # Some of the flags we use are not used by every compilation step of the test suite. In
+    # particular, we validate flags added to %{link_flags} (such as -lc++experimental) by
+    # trying them out with a compile-only command, which warns that they are unused.
     "-Wno-unused-command-line-argument",
+
     "-Wno-attributes",
     "-Wno-pessimizing-move",
     "-Wno-noexcept-type",
     "-Wno-aligned-allocation-unavailable",
     "-Wno-atomic-alignment",
     "-Wno-reserved-module-identifier",
-    '-Wdeprecated-copy',
-    '-Wdeprecated-copy-dtor',
-    "-Wshift-negative-value",
+
     # GCC warns about places where we might want to add sized allocation/deallocation
     # functions, but we know better what we're doing/testing in the test suite.
     "-Wno-sized-deallocation",
+
     # Turn off warnings about user-defined literals with reserved suffixes. Those are
     # just noise since we are testing the Standard Library itself.
     "-Wno-literal-suffix",  # GCC
     "-Wno-user-defined-literals",  # Clang
+
     # GCC warns about this when TEST_IS_CONSTANT_EVALUATED is used on a non-constexpr
     # function. (This mostly happens in C++11 mode.)
     # TODO(mordante) investigate a solution for this issue.
@@ -46,13 +74,7 @@
     # -Wstringop-overread and -Wstringop-overflow seem to be a bit buggy currently
     "-Wno-stringop-overread",
     "-Wno-stringop-overflow",
-    # These warnings should be enabled in order to support the MSVC
-    # team using the test suite; They enable the warnings below and
-    # expect the test suite to be clean.
-    "-Wsign-compare",
-    "-Wunused-variable",
-    "-Wunused-parameter",
-    "-Wunreachable-code",
+
     "-Wno-unused-local-typedef",
 
     # Disable warnings for extensions used in C++03
@@ -61,6 +83,7 @@
 
     # TODO(philnik) This fails with the PSTL.
     "-Wno-unknown-pragmas",
+
     # Don't fail compilation in case the compiler fails to perform the requested
     # loop vectorization.
     "-Wno-pass-failed",
@@ -75,9 +98,6 @@
 
     # We're not annotating all the APIs, since that's a lot of annotations compared to how many we actually care about
     "-Wno-nullability-completeness",
-
-    # Technically not a warning flag, but might as well be:
-    "-flax-vector-conversions=none",
 ]
 
 _allStandards = ["c++03", "c++11", "c++14", "c++17", "c++20", "c++23", "c++26"]
@@ -294,9 +314,10 @@ def getSuitableClangTidy(cfg):
         type=bool,
         default=True,
         help="Whether to enable warnings when compiling the test suite.",
-        actions=lambda warnings: [] if not warnings else
-            [AddOptionalWarningFlag(w) for w in _warningFlags] +
-            [AddCompileFlag("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER")],
+        actions=lambda warnings: ([AddCompileFlag("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER"),
+                                   AddFeature("enable-warnings"),
+                                   *(AddOptionalWarningFlag(w) for w in _enabledWarningFlags)] if warnings else []) + \
+                                   [AddOptionalWarningFlag(w) for w in _silencedWarningFlags],
     ),
     Parameter(
         name="use_sanitizer",

``````````

</details>


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


More information about the libcxx-commits mailing list