diff options
author | Clement Courbet <courbet@google.com> | 2018-05-23 07:58:41 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-05-23 07:58:41 +0000 |
commit | 1c0a15c4449f862711cb0df0548d4c83a6ff8554 (patch) | |
tree | 11b067847a8a8dde752f73cac605aae9e5a357e5 /clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h | |
parent | 9b412153bfc4d3bed29f9b6c259b4b8777cc488f (diff) | |
download | bcm5719-llvm-1c0a15c4449f862711cb0df0548d4c83a6ff8554.tar.gz bcm5719-llvm-1c0a15c4449f862711cb0df0548d4c83a6ff8554.zip |
[clang-tidy] new cppcoreguidelines-narrowing-conversions check.
Summary:
Checks for narrowing conversions, e.g.
int i = 0;
i += 0.1;
This has what some might consider false positives for:
i += ceil(d);
Reviewers: alexfh, hokein
Subscribers: srhines, nemanjai, mgorny, JDevlieghere, xazax.hun, kbarton
Differential Revision: https://reviews.llvm.org/D38455
llvm-svn: 333066
Diffstat (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h')
-rw-r--r-- | clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h new file mode 100644 index 00000000000..35f58bc220a --- /dev/null +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h @@ -0,0 +1,37 @@ +//===--- NarrowingConversionsCheck.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_CPPCOREGUIDELINES_NARROWING_CONVERSIONS_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NARROWING_CONVERSIONS_H + +#include "../ClangTidy.h" + +namespace clang { +namespace tidy { +namespace cppcoreguidelines { + +/// Checks for narrowing conversions, e.g: +/// int i = 0; +/// i += 0.1; +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.html +class NarrowingConversionsCheck : public ClangTidyCheck { +public: + NarrowingConversionsCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace cppcoreguidelines +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NARROWING_CONVERSIONS_H |