clang-tools
15.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
AssertSideEffectCheck.h
Go to the documentation of this file.
1
//===--- AssertSideEffectCheck.h - clang-tidy -------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ASSERTSIDEEFFECTCHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ASSERTSIDEEFFECTCHECK_H
11
12
#include "../ClangTidyCheck.h"
13
#include "llvm/ADT/SmallVector.h"
14
#include "llvm/ADT/StringRef.h"
15
#include <string>
16
17
namespace
clang
{
18
namespace
tidy {
19
namespace
bugprone {
20
21
/// Finds `assert()` with side effect.
22
///
23
/// The condition of `assert()` is evaluated only in debug builds so a
24
/// condition with side effect can cause different behavior in debug / release
25
/// builds.
26
///
27
/// There are two options:
28
///
29
/// - `AssertMacros`: A comma-separated list of the names of assert macros to
30
/// be checked.
31
/// - `CheckFunctionCalls`: Whether to treat non-const member and non-member
32
/// functions as they produce side effects. Disabled by default because it
33
/// can increase the number of false positive warnings.
34
class
AssertSideEffectCheck
:
public
ClangTidyCheck
{
35
public
:
36
AssertSideEffectCheck
(StringRef
Name
,
ClangTidyContext
*Context);
37
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
38
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
39
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
40
41
private
:
42
const
bool
CheckFunctionCalls;
43
const
StringRef RawAssertList;
44
SmallVector<StringRef, 5> AssertMacros;
45
const
std::vector<StringRef> IgnoredFunctions;
46
};
47
48
}
// namespace bugprone
49
}
// namespace tidy
50
}
// namespace clang
51
52
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ASSERTSIDEEFFECTCHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:115
clang::tidy::bugprone::AssertSideEffectCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition:
AssertSideEffectCheck.cpp:87
clang::tidy::bugprone::AssertSideEffectCheck
Finds assert() with side effect.
Definition:
AssertSideEffectCheck.h:34
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::bugprone::AssertSideEffectCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
AssertSideEffectCheck.cpp:114
clang::tidy::bugprone::AssertSideEffectCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
AssertSideEffectCheck.cpp:94
clang::tidy::bugprone::AssertSideEffectCheck::AssertSideEffectCheck
AssertSideEffectCheck(StringRef Name, ClangTidyContext *Context)
Definition:
AssertSideEffectCheck.cpp:76
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:67
Name
Token Name
Definition:
MacroToEnumCheck.cpp:89
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
Generated on Sun Jun 26 2022 13:27:10 for clang-tools by
1.8.17