diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-07-11 08:08:47 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-07-11 08:08:47 +0000 |
commit | 1c8b31753b0699960d314a67dba2c71ba832e6ae (patch) | |
tree | baa10f2e41cb0f56787cb9fe1776011537c8211b /clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h | |
parent | 780ce0f8e3505e7a3df0ee5f5d421d8e0e253079 (diff) | |
download | bcm5719-llvm-1c8b31753b0699960d314a67dba2c71ba832e6ae.tar.gz bcm5719-llvm-1c8b31753b0699960d314a67dba2c71ba832e6ae.zip |
[clang-tidy] Add a checker for implicit bool conversion of a bool*.
The goal is to find code like the example below, which is likely a typo
where someone meant to write "if (*b)".
bool *b = SomeFunction();
if (b) {
// b never dereferenced
}
This checker naturally has a relatively high false positive rate so it
applies some heuristics to avoid cases where the pointer is checked for
nullptr before being written.
Differential Revision: http://reviews.llvm.org/D4458
llvm-svn: 212797
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h new file mode 100644 index 00000000000..16c0d631eec --- /dev/null +++ b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.h @@ -0,0 +1,34 @@ +//===--- BoolPointerImplicitConversion.h - clang-tidy -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_BOOL_POINTER_IMPLICIT_CONV_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_BOOL_POINTER_IMPLICIT_CONV_H + +#include "../ClangTidy.h" + +namespace clang { +namespace tidy { + +/// \brief Checks for conditions based on implicit conversion from a bool +/// pointer to bool e.g. +/// bool *p; +/// if (p) { +/// // Never used in a pointer-specific way. +/// } +class BoolPointerImplicitConversion : public ClangTidyCheck { +public: + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_BOOL_POINTER_IMPLICIT_CONV_H + |