llvm-project/clang-tools-extra/unittests/clang-tidy
Richard 99217fa8a0 [clang-tidy] Recognize labelled statements when simplifying boolean exprs
Inside a switch the caseStmt() and defaultStmt() have a nested statement
associated with them.  Similarly, labelStmt() has a nested statement.
These statements were being missed when looking for a compound-if of the
form "if (x) return true; return false;" when the if is nested under one
of these labelling constructs.

Enhance the matchers to look for these nested statements using some
private matcher hasSubstatement() traversal matcher on case, default
and label statements.  Add the private matcher hasSubstatementSequence()
to match the compound "if (x) return true; return false;" pattern.

- Add unit tests for private matchers and corresponding test
  infrastructure
- Add corresponding test file readability-simplify-bool-expr-case.cpp.
- Fix variable name copy/paste error in readability-simplify-bool-expr.cpp.
- Drop the asserts, which were used only for debugging matchers.
- Run clang-format on the whole check.
- Move local functions out of anonymous namespace and declare state, per
  LLVM style guide
- Declare labels constexpr
- Declare visitor arguments as pointer to const
- Drop braces around simple control statements per LLVM style guide
- Prefer explicit arguments over default arguments to methods

Differential Revision: https://reviews.llvm.org/D56303

Fixes #27078
2022-01-28 16:09:46 -07:00
..
AddConstTest.cpp [clang-tidy] implement utility-function to add 'const' to variables 2020-01-03 20:37:47 +01:00
CMakeLists.txt [clang-tidy] Recognize labelled statements when simplifying boolean exprs 2022-01-28 16:09:46 -07:00
ClangTidyDiagnosticConsumerTest.cpp [libtooling][clang-tidy] Fix crashing on rendering invalid SourceRanges 2021-11-29 09:56:43 +01:00
ClangTidyOptionsTest.cpp [clang-tidy] Remove OptionError 2021-03-01 17:55:17 +00:00
ClangTidyTest.h [clang] Replace report_fatal_error(std::string) uses with report_fatal_error(Twine) 2021-10-06 11:43:19 +01:00
DeclRefExprUtilsTest.cpp [clang-tidy] Add unit tests for `DeclRefExprUtils`. 2021-11-24 16:47:55 +01:00
GlobListTest.cpp [clang-tidy][NFC] Move CachedGlobList to GlobList.h 2021-12-04 08:50:49 +00:00
GoogleModuleTest.cpp
IncludeInserterTest.cpp Make sure Objective-C category support in IncludeSorter handles top-level imports 2020-10-26 12:24:43 -07:00
LLVMModuleTest.cpp [clang-tidy] Fix pr48613: "llvm-header-guard uses a reserved identifier" 2021-11-30 12:43:35 +13:00
NamespaceAliaserTest.cpp
ObjCModuleTest.cpp
OptionsProviderTest.cpp [clang-tidy] Use vfs::FileSystem when getting config 2020-11-07 19:18:02 +00:00
OverlappingReplacementsTest.cpp
ReadabilityModuleTest.cpp [clang-tidy] Recognize labelled statements when simplifying boolean exprs 2022-01-28 16:09:46 -07:00
TransformerClangTidyCheckTest.cpp [libtooling][clang-tidy] Fix diagnostics not highlighting fed SourceRanges 2021-04-10 16:43:44 +02:00
UsingInserterTest.cpp