[clang-tools-extra] [clang-tidy] In bugprone-unused-return-value allow cast to void for pre-C++26 by default (PR #171618)

via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 10 08:10:01 PST 2025


================
@@ -145,7 +146,9 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
                                             "^::std::errc$;"
                                             "^::std::expected$;"
                                             "^::boost::system::error_code$"))),
-      AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
+      AllowCastToVoid(
+          Options.get("AllowCastToVoid", Context->getLangOpts().LangStd <
+                                             LangStandard::lang_cxx26)) {}
----------------
maflcko wrote:

yes, I understand that this makes it a bit more permissive for 23-or-less. However, I think this is desirable, because:

* There is no risk or downside to allow casting to void to silence the warning in normal code, compared to the other methods of silencing the warning.
* In fact allowing `(void)` seems better than only allowing a `NOLINT` or a `[[maybe_unused]]`
* This makes this bugprone check readily applicable to more codebases without extra steps of having to rewrite `(void)` casts to something else, or having to toggle options.
* Once the codebases transition to C++26, they may transition to the `_` placeholder, introduced for this purpose.

This all seem like benefits to me, and I don't see any downside or risk. But maybe I am missing something obvious?

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


More information about the cfe-commits mailing list