clang-tools  14.0.0git
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.
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 std::string RawAssertList;
44  SmallVector<StringRef, 5> AssertMacros;
45 };
46 
47 } // namespace bugprone
48 } // namespace tidy
49 } // namespace clang
50 
51 #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:81
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:54
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::bugprone::AssertSideEffectCheck::AssertSideEffectCheck
AssertSideEffectCheck(StringRef Name, ClangTidyContext *Context)
Definition: AssertSideEffectCheck.cpp:71
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27