clang-tools
8.0.0
llvm.src
tools
clang
tools
extra
clang-tidy
bugprone
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
31
class
TooSmallLoopVariableCheck
:
public
ClangTidyCheck
{
32
public
:
33
TooSmallLoopVariableCheck
(StringRef
Name
,
ClangTidyContext
*Context)
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
clang::tidy::bugprone::TooSmallLoopVariableCheck::TooSmallLoopVariableCheck
TooSmallLoopVariableCheck(StringRef Name, ClangTidyContext *Context)
Definition:
TooSmallLoopVariableCheck.h:33
clang::tidy::bugprone::TooSmallLoopVariableCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
The matcher for loops with suspicious integer loop variable.
Definition:
TooSmallLoopVariableCheck.cpp:44
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:127
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:28
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition:
ClangdServer.cpp:60
clang::tidy::bugprone::TooSmallLoopVariableCheck
This check gives a warning if a loop variable has a too small type which might not be able to represe...
Definition:
TooSmallLoopVariableCheck.h:31
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:100
clang::tidy::bugprone::TooSmallLoopVariableCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
TooSmallLoopVariableCheck.cpp:137
Generated on Thu Jan 24 2019 17:59:25 for clang-tools by
1.8.13