clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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'.
41 class StringReferenceMemberCheck : public ClangTidyCheck {
42 public:
43 StringReferenceMemberCheck(StringRef Name, ClangTidyContext *Context)
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
clang::tidy::google::runtime::StringReferenceMemberCheck
Finds members of type const string&.
Definition: StringReferenceMemberCheck.h:41
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::google::runtime::StringReferenceMemberCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition: StringReferenceMemberCheck.cpp:22
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
clang::tidy::google::runtime::StringReferenceMemberCheck::StringReferenceMemberCheck
StringReferenceMemberCheck(StringRef Name, ClangTidyContext *Context)
Definition: StringReferenceMemberCheck.h:43
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
clang::tidy::google::runtime::StringReferenceMemberCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: StringReferenceMemberCheck.cpp:41
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121