clang-tools  6.0.0
StringReferenceMemberCheck.h
Go to the documentation of this file.
1 //===--- StringReferenceMemberCheck.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_GOOGLE_STRINGREFERENCEMEMBERCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_STRINGREFERENCEMEMBERCHECK_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace google {
18 namespace runtime {
19 
20 /// Finds members of type `const string&`.
21 ///
22 /// const string reference members are generally considered unsafe as they can
23 /// be created from a temporary quite easily.
24 ///
25 /// \code
26 /// struct S {
27 /// S(const string &Str) : Str(Str) {}
28 /// const string &Str;
29 /// };
30 /// S instance("string");
31 /// \endcode
32 ///
33 /// In the constructor call a string temporary is created from `const char *`
34 /// and destroyed immediately after the call. This leaves around a dangling
35 /// reference.
36 ///
37 /// This check emit warnings for both `std::string` and `::string` const
38 /// reference members.
39 ///
40 /// Corresponding cpplint.py check name: 'runtime/member_string_reference'.
42 public:
44  : ClangTidyCheck(Name, Context) {}
45  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
46  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
47 };
48 
49 } // namespace runtime
50 } // namespace google
51 } // namespace tidy
52 } // namespace clang
53 
54 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_STRINGREFERENCEMEMBERCHECK_H
StringHandle Name
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
StringReferenceMemberCheck(StringRef Name, ClangTidyContext *Context)
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.