[libcxx-commits] [libcxx] [libc++] Fix the enable_warnings=True|False Lit parameter (PR #214113)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 6 06:16:22 PDT 2026
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/214113
>From 10039273db8d42a927dae180ce74598349540856 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 23 Apr 2026 15:58:46 -0400
Subject: [PATCH 1/2] [libc++] Fix the enable_warnings=True|False Lit parameter
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.
---
.../diagnostics/unused_variables.verify.cpp | 3 +
libcxx/test/selftest/pass.cpp/werror.pass.cpp | 3 +
libcxx/test/selftest/sh.cpp/werror.sh.cpp | 3 +
libcxx/utils/libcxx/test/params.py | 55 +++++++++++++------
4 files changed, 47 insertions(+), 17 deletions(-)
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",
>From 4318972120ac4d98d4d8c4f133e187a1f59ed6fb Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 6 Aug 2026 09:14:44 -0400
Subject: [PATCH 2/2] Disable -Werror instead
---
libcxx/test/selftest/pass.cpp/werror.pass.cpp | 25 --------
libcxx/test/selftest/sh.cpp/werror.sh.cpp | 26 --------
libcxx/utils/libcxx/test/params.py | 60 ++++++-------------
3 files changed, 19 insertions(+), 92 deletions(-)
delete mode 100644 libcxx/test/selftest/pass.cpp/werror.pass.cpp
delete mode 100644 libcxx/test/selftest/sh.cpp/werror.sh.cpp
diff --git a/libcxx/test/selftest/pass.cpp/werror.pass.cpp b/libcxx/test/selftest/pass.cpp/werror.pass.cpp
deleted file mode 100644
index f789966f98631..0000000000000
--- a/libcxx/test/selftest/pass.cpp/werror.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// XFAIL: *
-
-// Make sure that even a simple unused variable warning is treated as an
-// error in the test suite. This is to make sure the test suite always runs
-// with -Werror.
-
-// ADDITIONAL_COMPILE_FLAGS: -Wunused-variable
-
-// 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
deleted file mode 100644
index b5d445ac10018..0000000000000
--- a/libcxx/test/selftest/sh.cpp/werror.sh.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// XFAIL: *
-
-// Make sure that even a simple unused variable warning is treated as an
-// error in the test suite, including in .sh.cpp tests.
-
-// 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}
-
-int main(int, char**) {
- int foo;
- return 0;
-}
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 476a4c6aabae6..6aededc93fd76 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -14,59 +14,30 @@
from libcxx.test.features.compiler import _isClang, _isAppleClang, _isGCC, _isMSVC
-# Warnings that we enable when running the test suite with warnings enabled, which is
-# controlled by `--param enable_warnings=True|False`.
-_enabledWarningFlags = [
- "-Werror",
+_warningFlags = [
"-Wall",
"-Wctad-maybe-unsupported",
"-Wextra",
"-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.
@@ -74,7 +45,13 @@
# -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
@@ -83,7 +60,6 @@
# 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",
@@ -98,6 +74,9 @@
# 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"]
@@ -309,15 +288,14 @@ def getSuitableClangTidy(cfg):
actions=lambda is_system: [AddFeature("stdlib=system")] if is_system else [],
),
Parameter(
- name="enable_warnings",
+ name="enable_werror",
choices=[True, False],
type=bool,
default=True,
- help="Whether to enable warnings when compiling the test suite.",
- 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],
+ help="Whether to treat warnings as errors when compiling the test suite.",
+ actions=lambda werror: [AddOptionalWarningFlag(w) for w in _warningFlags] +
+ [AddCompileFlag("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER")] +
+ ([AddCompileFlag("-Werror")] if werror else []),
),
Parameter(
name="use_sanitizer",
More information about the libcxx-commits
mailing list