clang-tools  8.0.0
TooSmallLoopVariableCheck.h
Go to the documentation of this file.
1 //===--- TooSmallLoopVariableCheck.h - clang-tidy ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TOOSMALLLOOPVARIABLECHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TOOSMALLLOOPVARIABLECHECK_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace bugprone {
18 
19 /// This check gives a warning if a loop variable has a too small type which
20 /// might not be able to represent all values which are part of the whole range
21 /// in which the loop iterates.
22 /// If the loop variable's type is too small we might end up in an infinite
23 /// loop. Example:
24 /// \code
25 /// long size = 294967296l;
26 /// for (short i = 0; i < size; ++i) {} { ... }
27 /// \endcode
28 ///
29 /// For the user-facing documentation see:
30 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-too-small-loop-variable.html
32 public:
34  : ClangTidyCheck(Name, Context) {}
35  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37 };
38 
39 } // namespace bugprone
40 } // namespace tidy
41 } // namespace clang
42 
43 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TOOSMALLLOOPVARIABLECHECK_H
TooSmallLoopVariableCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
The matcher for loops with suspicious integer loop variable.
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
static constexpr llvm::StringLiteral Name
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
This check gives a warning if a loop variable has a too small type which might not be able to represe...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.