From b54831eb35fa314e41b0c8625a62cc1e3a1f63f8 Mon Sep 17 00:00:00 2001 From: esadomer <54475303+esadomer@users.noreply.github.com> Date: Tue, 13 Oct 2026 19:50:24 +0300 Subject: [PATCH 1/2] gh-159336: Accept GCC warnings without an option suffix --- Lib/test/test_tools/test_check_warnings.py | 29 ++++++++++++++++++++++ Tools/build/check_warnings.py | 4 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Lib/test/test_tools/test_check_warnings.py diff --git a/Lib/test/test_tools/test_check_warnings.py b/Lib/test/test_tools/test_check_warnings.py new file mode 100644 index 000000000000000..3dee4c8880d8ea9 --- /dev/null +++ b/Lib/test/test_tools/test_check_warnings.py @@ -0,0 +1,29 @@ +import importlib +import unittest + +from test.test_tools import imports_under_tool, skip_if_missing + + +skip_if_missing("build") +with imports_under_tool("build"): + check_warnings = importlib.import_module("check_warnings") + + +class CheckWarningsTests(unittest.TestCase): + def test_warning_options(self): + for compiler, suffix, option in ( + ("gcc", "", ""), + ("gcc", " [-Wunused-variable]", "-Wunused-variable"), + ("clang", " [-Wunused-variable]", "-Wunused-variable"), + ): + with self.subTest(compiler=compiler, suffix=suffix): + warnings = check_warnings.extract_warnings_from_compiler_output( + "source.c:1:2: warning: example" + suffix, compiler) + self.assertEqual(warnings, [{ + "file": "source.c", "line": "1", "column": "2", + "message": "example", "option": option, + }]) + + +if __name__ == "__main__": + unittest.main() diff --git a/Tools/build/check_warnings.py b/Tools/build/check_warnings.py index 44ccf9708ad72f0..5041641ff2a4171 100644 --- a/Tools/build/check_warnings.py +++ b/Tools/build/check_warnings.py @@ -100,7 +100,9 @@ def extract_warnings_from_compiler_output( "line": match.group("line"), "column": match.group("column"), "message": match.group("message"), - "option": match.group("option").lstrip("[").rstrip("]"), + "option": (match.group("option") or "") + .lstrip("[") + .rstrip("]"), }) except AttributeError: print( From 5d9affd19b6bad5743a0378cb27ea676754c8285 Mon Sep 17 00:00:00 2001 From: esadomer <54475303+esadomer@users.noreply.github.com> Date: Tue, 13 Oct 2026 20:08:29 +0300 Subject: [PATCH 2/2] gh-159336: Add NEWS entry for warnings-optional-gcc-option --- .../Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst b/Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst new file mode 100644 index 000000000000000..072bd6eb0f75c6f --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst @@ -0,0 +1,2 @@ +Fix ``Tools/build/check_warnings.py`` to accept GCC diagnostics that +omit the warning-option suffix.