clang-tools 6.0.0

AssertSideEffectCheck.h
Go to the documentation of this file.
1 //===--- AssertSideEffectCheck.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_ASSERTSIDEEFFECTCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ASSERTSIDEEFFECTCHECK_H
12
13 #include "../ClangTidy.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include <string>
17
18 namespace clang {
19 namespace tidy {
20 namespace bugprone {
21
22 /// Finds `assert()` with side effect.
23 ///
24 /// The condition of `assert()` is evaluated only in debug builds so a
25 /// condition with side effect can cause different behavior in debug / release
26 /// builds.
27 ///
28 /// There are two options:
29 ///
30 /// - `AssertMacros`: A comma-separated list of the names of assert macros to
31 /// be checked.
32 /// - `CheckFunctionCalls`: Whether to treat non-const member and non-member
33 /// functions as they produce side effects. Disabled by default because it
34 /// can increase the number of false positive warnings.
35 class AssertSideEffectCheck : public ClangTidyCheck {
36 public:
37 AssertSideEffectCheck(StringRef Name, ClangTidyContext *Context);
38 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
39 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
40 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
41
42 private:
43 const bool CheckFunctionCalls;
44 const std::string RawAssertList;
45 SmallVector<StringRef, 5> AssertMacros;
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::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:81
clang::tidy::bugprone::AssertSideEffectCheck
Finds assert() with side effect.
Definition: AssertSideEffectCheck.h:35
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
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:102
clang::tidy::bugprone::AssertSideEffectCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: AssertSideEffectCheck.cpp:86
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::bugprone::AssertSideEffectCheck::AssertSideEffectCheck
AssertSideEffectCheck(StringRef Name, ClangTidyContext *Context)
Definition: AssertSideEffectCheck.cpp:72
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:99
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104