NagyDonat wrote:

> Looking at the documentation and the default `CheckedFunctions`, I read this 
> check as catching cases where discarding the return value is itself 
> suspicious or wrong.

Yes, the default `CheckedFunctions` lists functions where discarding the return 
value is suspicious. (I don't think that we can say that it is definitely 
_wrong_ without any knowledge about the context.)

However, when the programmers write a `(void)` cast, they say that "yes, I know 
that this is suspicious in general, but I checked that in this particular 
context this is the right thing to do". The default behavior of Clang Tidy 
_must_ respect the judgement of the users, because they are professionals who 
know _much more_ about their own code than our shallow AST-based automated 
checks. (The checkers may have a paranoid analysis mode that spams the user 
with "I see you wanted this, but did you _really_ want it?", but it is a 
terrible experience, so it must not be the default one.) 

> If the discard is intentional and safe, an explicit `// 
> NOLINT(bugprone-unused-return-value)` makes that exception visible to future 
> reviewers. A plain `(void)` cast is much easier to overlook.

But `// NOLINT(bugprone-unused-return-value)` has a _HUGE_ drawback that it is 
only understood by clang-tidy, while `(void)` is the well-established standard 
notation for "I'm intentionally discarding this value" which is widely used in 
the industry and also recognized by many other code analysis tools.

https://github.com/llvm/llvm-project/pull/200173
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to