[PATCH] D84898: clang-tidy] Add new checker for complex conditions with no meaning

Vince Bridgers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 29 17:24:35 PDT 2020


vabridgers created this revision.
Herald added subscribers: cfe-commits, phosek, Charusso, mgorny.
Herald added a project: clang.
vabridgers requested review of this revision.

This checker finds cases where relational expressions have no meaning.
For example, (x <= y <= z) has no meaning, but just happens to parse to
something deterministic. (x <= y <= z) is parsed to ((x <= y) <= z).
The (x<=y) returns a boolean value which is promoted to an integral
context, 0 (for false) or 1 (for true). So when (x <= y) the expression
becomes (1 <= z) and when (x > y) the expression becomes (0 <= z). When
asked to give all warnings, gcc warns about this. While this may be the
intention in some programming contexts, it may not have been what the
programmer really wanted in all contexts. So it's best to implement this as a
tidy check to start with, get some experience using it, then perhaps promote
this check to a diagnostic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84898

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.cpp
  clang-tools-extra/clang-tidy/misc/ComplexConditionsCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-complex-conditions.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-complex-conditions.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84898.281768.patch
Type: text/x-patch
Size: 11547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200730/abbc310f/attachment.bin>


More information about the cfe-commits mailing list