https://github.com/gamesh411 updated https://github.com/llvm/llvm-project/pull/200173
From 46ac1618dd287acb91fce09a7e525fda12c4ee4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= <[email protected]> Date: Thu, 28 May 2026 14:55:21 +0200 Subject: [PATCH 1/2] [clang-tidy] Change AllowCastToVoid default to true in bugprone-unused-return-value Casting to (void) is the standard C/C++ idiom for intentionally discarding a return value. The check should respect this by default rather than requiring users to opt in. Both coding standard aliases that used this check (cert-err33-c and the now-removed hicpp-ignored-remove-result) overrode AllowCastToVoid to true, confirming that (void) casts are a legitimate suppression mechanism. --- .../clang-tidy/bugprone/UnusedReturnValueCheck.cpp | 2 +- clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp | 1 - clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../docs/clang-tidy/checks/bugprone/unused-return-value.rst | 2 +- .../checkers/bugprone/unused-return-value-custom.cpp | 1 - .../checkers/bugprone/unused-return-value-remove.cpp | 2 +- .../test/clang-tidy/checkers/bugprone/unused-return-value.cpp | 3 +-- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp index c5792cd17b9b2e..9156c32078e9cd 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp @@ -145,7 +145,7 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(StringRef Name, "^::std::errc$;" "^::std::expected$;" "^::boost::system::error_code$"))), - AllowCastToVoid(Options.get("AllowCastToVoid", false)) {} + AllowCastToVoid(Options.get("AllowCastToVoid", true)) {} UnusedReturnValueCheck::UnusedReturnValueCheck( StringRef Name, ClangTidyContext *Context, diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp index ee1ce59d80b0de..4e952b59cdfe6b 100644 --- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp @@ -353,7 +353,6 @@ class CERTModule : public ClangTidyModule { Opts["cert-arr39-c.WarnOnSizeOfPointerToAggregate"] = "false"; Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU"; Opts["cert-err33-c.CheckedFunctions"] = CertErr33CCheckedFunctions; - Opts["cert-err33-c.AllowCastToVoid"] = "true"; Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "false"; Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "false"; return Options; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 0b3bb091307e75..8e496edbb8d4ee 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -423,6 +423,10 @@ Changes in existing checks ``std::get_temporary_buffer`` to the default list of unsafe functions. (This function is unsafe, useless, deprecated in C++17 and removed in C++20). +- Improved :doc:`bugprone-unused-return-value + <clang-tidy/checks/bugprone/unused-return-value>` check by changing the + default of the ``AllowCastToVoid`` option from `false` to `true`. + - Improved :doc:`bugprone-use-after-move <clang-tidy/checks/bugprone/use-after-move>` check: diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst index 725403a6eb8183..9395d9fef5b473 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst @@ -63,7 +63,7 @@ Options .. option:: AllowCastToVoid - Controls whether casting return values to ``void`` is permitted. Default: `false`. + Controls whether casting return values to ``void`` is permitted. Default: `true`. :doc:`cert-err33-c <../cert/err33-c>` is an alias of this check that checks a fixed and large set of standard library functions. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-custom.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-custom.cpp index 3035183573ccd7..5bf21d20d3302f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-custom.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-custom.cpp @@ -53,7 +53,6 @@ void warning() { // CHECK-MESSAGES: [[@LINE-1]]:4: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors (void)fun(); - // CHECK-MESSAGES: [[@LINE-1]]:9: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors ns::Outer::Inner ObjA1; ObjA1.memFun(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-remove.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-remove.cpp index 2934db6dd2d2cd..fee75469ca2974 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-remove.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-remove.cpp @@ -1,5 +1,5 @@ // RUN: %check_clang_tidy %s bugprone-unused-return-value %t -- \ -// RUN: -config='{CheckOptions: {bugprone-unused-return-value.CheckedFunctions: "^::std::remove$;^::std::remove_if$;^::std::unique$", bugprone-unused-return-value.CheckedReturnTypes: "", bugprone-unused-return-value.AllowCastToVoid: true}}' +// RUN: -config='{CheckOptions: {bugprone-unused-return-value.CheckedFunctions: "^::std::remove$;^::std::remove_if$;^::std::unique$", bugprone-unused-return-value.CheckedReturnTypes: ""}}' // RUN: %check_clang_tidy -check-suffixes=NOCAST %s bugprone-unused-return-value %t -- \ // RUN: -config='{CheckOptions: {bugprone-unused-return-value.CheckedFunctions: "^::std::remove$;^::std::remove_if$;^::std::unique$", bugprone-unused-return-value.CheckedReturnTypes: "", bugprone-unused-return-value.AllowCastToVoid: false}}' diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp index 3fa87b94dc6b49..9aaa8d3c8a35fe 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp @@ -1,5 +1,4 @@ -// RUN: %check_clang_tidy %s bugprone-unused-return-value %t -- \ -// RUN: --config="{CheckOptions: {bugprone-unused-return-value.AllowCastToVoid: true}}" -- -fexceptions +// RUN: %check_clang_tidy %s bugprone-unused-return-value %t -- -- -fexceptions #include <vector> #include <memory> From afd9ee1266af27fe184f74f5f62ca49794e95837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= <[email protected]> Date: Thu, 17 Sep 2026 11:56:14 +0200 Subject: [PATCH 2/2] move release note to potentially breaking changes --- clang-tools-extra/docs/ReleaseNotes.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md index 5e77736293c37c..fb1cb91e2eeab3 100644 --- a/clang-tools-extra/docs/ReleaseNotes.md +++ b/clang-tools-extra/docs/ReleaseNotes.md @@ -56,6 +56,10 @@ infrastructure are described first, followed by tool-specific sections. ### Potentially Breaking Changes +- Improved {doc}`bugprone-unused-return-value + <clang-tidy/checks/bugprone/unused-return-value>` check by changing the + default of the `AllowCastToVoid` option from `false` to `true`. + - The deprecated `zircon` clang-tidy module has been removed. Users of `zircon-temporary-objects` should migrate to {doc}`fuchsia-temporary-objects <clang-tidy/checks/fuchsia/temporary-objects>`. @@ -188,10 +192,6 @@ infrastructure are described first, followed by tool-specific sections. <clang-tidy/checks/bugprone/std-namespace-modification>` when checking lambda closure types used as template arguments. -- Improved {doc}`bugprone-unused-return-value - <clang-tidy/checks/bugprone/unused-return-value>` check by changing the - default of the `AllowCastToVoid` option from `false` to `true`. - - Improved {doc}`cppcoreguidelines-missing-std-forward <clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by diagnosing unforwarded `auto&&` parameters in C++20 abbreviated function templates. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
