clang-tools
3.8.0
Main Page
Namespaces
Classes
Files
File List
File Members
work
release-test
final
docsbuild
llvm.src
tools
clang
tools
extra
clang-tidy
readability
ContainerSizeEmptyCheck.h
Go to the documentation of this file.
1
//===--- ContainerSizeEmptyCheck.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_READABILITY_CONTAINERSIZEEMPTYCHECK_H
11
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
12
13
#include "../ClangTidy.h"
14
15
namespace
clang {
16
namespace
tidy {
17
namespace
readability {
18
19
/// Checks whether a call to the `size()` method can be replaced with a call to
20
/// `empty()`.
21
///
22
/// The emptiness of a container should be checked using the `empty()` method
23
/// instead of the `size()` method. It is not guaranteed that `size()` is a
24
/// constant-time function, and it is generally more efficient and also shows
25
/// clearer intent to use `empty()`. Furthermore some containers may implement
26
/// the `empty()` method but not implement the `size()` method. Using `empty()`
27
/// whenever possible makes it easier to switch to another container in the
28
/// future.
29
class
ContainerSizeEmptyCheck
:
public
ClangTidyCheck
{
30
public
:
31
ContainerSizeEmptyCheck
(StringRef
Name
,
ClangTidyContext
*
Context
);
32
void
registerMatchers
(ast_matchers::MatchFinder *
Finder
)
override
;
33
void
check
(
const
ast_matchers::MatchFinder::MatchResult &
Result
)
override
;
34
};
35
36
}
// namespace readability
37
}
// namespace tidy
38
}
// namespace clang
39
40
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
clang::tidy::readability::ContainerSizeEmptyCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
ContainerSizeEmptyCheck.cpp:87
Name
StringHandle Name
Definition:
PreprocessorTracker.cpp:525
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition:
ClangTidy.cpp:188
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:102
clang::tidy::readability::ContainerSizeEmptyCheck
Checks whether a call to the size() method can be replaced with a call to empty().
Definition:
ContainerSizeEmptyCheck.h:29
clang::tidy::readability::ContainerSizeEmptyCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition:
ContainerSizeEmptyCheck.cpp:54
Context
ClangTidyContext & Context
Definition:
ClangTidy.cpp:93
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:124
clang::tidy::readability::ContainerSizeEmptyCheck::ContainerSizeEmptyCheck
ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context)
Definition:
ContainerSizeEmptyCheck.cpp:50
Result
const NamedDecl * Result
Definition:
USRFinder.cpp:121
Generated on Mon Mar 7 2016 09:54:11 for clang-tools by
1.8.6