[PATCH] D132786: [clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 29 08:06:57 PDT 2022


njames93 added a comment.

In D132786#3755390 <https://reviews.llvm.org/D132786#3755390>, @dodohand wrote:

> IMO you have just introduced a bug, not fixed one.
> A lambda expression in an if statement condition clause is exactly the kind of thing that this checker was designed to flag.
> The BARR group coding guideline, with which this is intended to comply in spirit, makes no exception for lambda expressions. (see 8.2c of https://barrgroup.com/sites/default/files/barr_c_coding_standard_2018.pdf)
>
> It would seem to me that rather than this change as a default behavior, it would be better if @njames93 created an option flag for this checker which enabled this exclusion as a special case. This would preserve the intent of the original check, while also allowing the use case which njames93 has in mind.
>
> Is it possible to retroactively reject/un-commit a contribution?

Granted that the coding guidelines this was intended for are designed for writing embedded C code, there was never any need to consider lambdas. As such, this change just makes the check a little bit more useful on C++ codebases.
Going by the name of this, it gives the impression that we are trying to detect bugs where an equality comparison was intended, or handle the case when an assignment isn't executed due to things like short circuiting rules. Neither of these use cases are expected when the assignment appears in the body of a lambda 
I'd be happy to support this as an option though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132786/new/

https://reviews.llvm.org/D132786



More information about the cfe-commits mailing list