[clang-tools-extra] [clang-tidy] In bugprone-unused-return-value allow cast to void for pre-C++26 by default (PR #171618)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 10 18:23:48 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)) {}
----------------
zwuis wrote:
Libc++ is applying `[[nodiscard]]` following [its coding guidelines](https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant). Changing the default value make clang-tidy be same strict as compiler warning, which is not the way to go.
> * In fact allowing `(void)` seems better than only allowing a `NOLINT` or a `[[maybe_unused]]`
1. There is another option to silence the warning by modifying code as `std::ignore = ...;`.
2. I don't think it's clear that which is better. I think it's personal preference/preference of the project.
> * 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.
I don't see "make this check realily applicable". I took a glance at the default values and explanation of other options of this check and they seem to be reasonable.
> * Once the codebases transition to C++26, they may transition to the `_` placeholder, introduced for this purpose.
I don't see the relation between this purpose and the name of this checker. It would be better to disable this check and add another check to do it.
https://github.com/llvm/llvm-project/pull/171618
More information about the cfe-commits
mailing list