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.
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
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
StringHandle Name
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
AssertSideEffectCheck(StringRef Name, ClangTidyContext *Context)
std::map< std::string, std::string > OptionMap
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.