[PATCH] D127114: new clang-tidy checker for assignments within condition clause of if statement

dodohand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 6 08:08:05 PDT 2022


dodohand added inline comments.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:9
+Finds these assignments even within multiple sets of parentheses which is often appropriate to structure multi-part condition statements.
+Finds these assignments even within multiple sets of paretheses which disables the compiler -Wparentheses check which one would otherwise like to rely on to find accidental assignment.
+The identified assignments violate BARR group "Rule 8.2.c". See: https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements
----------------
gribozavr2 wrote:
> Why not improve `-Wparentheses` to catch these cases too?
IMHO, `-Wparentheses` isn't broken. Its "disable warning by an extra set of parentheses" behavior has been around for a long time and is common across gcc and clang... it just isn't what is called for when trying to ensure that accidental assignments aren't occurring in even slightly complicated condition statements, or when trying to comply with BARR-group coding standard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127114



More information about the cfe-commits mailing list