diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2018-04-05 14:51:01 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2018-04-05 14:51:01 +0000 |
| commit | be92ce14e13708c96eac3fe6da8c7019e24b3e2a (patch) | |
| tree | 8b7a1375c939a4f1bddef3780a19c68eab421ed2 | |
| parent | 92357a233679fb46957e8daeebfa44aaf9095686 (diff) | |
| download | bcm5719-llvm-be92ce14e13708c96eac3fe6da8c7019e24b3e2a.tar.gz bcm5719-llvm-be92ce14e13708c96eac3fe6da8c7019e24b3e2a.zip | |
[clang-tidy] Remove google-runtime-member-string-references
This is triggering on a pattern that's both too broad (const
std::string& members can be used safely) and too narrow (std::string is
not the only class with this problem). It has a very low true positive
rate, just remove it until we find a better solution for dangling string
references.
llvm-svn: 329292
9 files changed, 2 insertions, 188 deletions
diff --git a/clang-tools-extra/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml b/clang-tools-extra/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml index d35e81d9694..7b06aba7375 100644 --- a/clang-tools-extra/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml +++ b/clang-tools-extra/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml @@ -115,10 +115,6 @@ Checks: Description:
Name: google-runtime-int
- Category: Google Style Guide
- Label: Find const string references
- Description:
- Name: google-runtime-member-string-references
- - Category: Google Style Guide
Label: Find zero-length memsets
Description:
Name: google-runtime-memset
diff --git a/clang-tools-extra/clang-tidy/google/CMakeLists.txt b/clang-tools-extra/clang-tidy/google/CMakeLists.txt index 5f1eb2334e8..1a7dd8712f8 100644 --- a/clang-tools-extra/clang-tidy/google/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt @@ -12,7 +12,6 @@ add_clang_library(clangTidyGoogleModule IntegerTypesCheck.cpp NonConstReferences.cpp OverloadedUnaryAndCheck.cpp - StringReferenceMemberCheck.cpp TodoCommentCheck.cpp UnnamedNamespaceInHeaderCheck.cpp UsingNamespaceDirectiveCheck.cpp diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp index aa1802de0ee..8962f7f6665 100644 --- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -24,7 +24,6 @@ #include "IntegerTypesCheck.h" #include "NonConstReferences.h" #include "OverloadedUnaryAndCheck.h" -#include "StringReferenceMemberCheck.h" #include "TodoCommentCheck.h" #include "UnnamedNamespaceInHeaderCheck.h" #include "UsingNamespaceDirectiveCheck.h" @@ -60,8 +59,6 @@ class GoogleModule : public ClangTidyModule { "google-runtime-operator"); CheckFactories.registerCheck<runtime::NonConstReferences>( "google-runtime-references"); - CheckFactories.registerCheck<runtime::StringReferenceMemberCheck>( - "google-runtime-member-string-references"); CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>( "google-readability-casting"); CheckFactories.registerCheck<readability::TodoCommentCheck>( diff --git a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp b/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp deleted file mode 100644 index f3a7bd99209..00000000000 --- a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===--- StringReferenceMemberCheck.cpp - clang-tidy ------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "StringReferenceMemberCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/ASTMatchers/ASTMatchers.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace google { -namespace runtime { - -void StringReferenceMemberCheck::registerMatchers( - ast_matchers::MatchFinder *Finder) { - // Only register the matchers for C++; the functionality currently does not - // provide any benefit to other languages, despite being benign. - if (!getLangOpts().CPlusPlus) - return; - - // Look for const references to std::string or ::string. - auto String = anyOf(namedDecl(hasName("::std::string")), - namedDecl(hasName("::string"))); - auto ConstString = qualType(isConstQualified(), hasDeclaration(String)); - - // Ignore members in template instantiations. - Finder->addMatcher( - fieldDecl(hasType(references(ConstString)), unless(isInstantiated())) - .bind("member"), - this); -} - -void StringReferenceMemberCheck::check(const MatchFinder::MatchResult &Result) { - const auto *Member = Result.Nodes.getNodeAs<FieldDecl>("member"); - diag(Member->getLocStart(), "const string& members are dangerous; it is much " - "better to use alternatives, such as pointers or " - "simple constants"); -} - -} // namespace runtime -} // namespace google -} // namespace tidy -} // namespace clang diff --git a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.h b/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.h deleted file mode 100644 index 5a39fd9b372..00000000000 --- a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.h +++ /dev/null @@ -1,54 +0,0 @@ -//===--- StringReferenceMemberCheck.h - clang-tidy ----------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_STRINGREFERENCEMEMBERCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_STRINGREFERENCEMEMBERCHECK_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace google { -namespace runtime { - -/// Finds members of type `const string&`. -/// -/// const string reference members are generally considered unsafe as they can -/// be created from a temporary quite easily. -/// -/// \code -/// struct S { -/// S(const string &Str) : Str(Str) {} -/// const string &Str; -/// }; -/// S instance("string"); -/// \endcode -/// -/// In the constructor call a string temporary is created from `const char *` -/// and destroyed immediately after the call. This leaves around a dangling -/// reference. -/// -/// This check emit warnings for both `std::string` and `::string` const -/// reference members. -/// -/// Corresponding cpplint.py check name: 'runtime/member_string_reference'. -class StringReferenceMemberCheck : public ClangTidyCheck { -public: - StringReferenceMemberCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace runtime -} // namespace google -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_STRINGREFERENCEMEMBERCHECK_H diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e71e616a397..49ab862a7d9 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -188,6 +188,8 @@ Improvements to clang-tidy - The 'misc-unused-raii' check was renamed to :doc:`bugprone-unused-raii <clang-tidy/checks/bugprone-unused-raii>` +- The 'google-runtime-member-string-references' check was removed. + Improvements to include-fixer ----------------------------- diff --git a/clang-tools-extra/docs/clang-tidy/checks/google-runtime-member-string-references.rst b/clang-tools-extra/docs/clang-tidy/checks/google-runtime-member-string-references.rst deleted file mode 100644 index bc4f0ee87dc..00000000000 --- a/clang-tools-extra/docs/clang-tidy/checks/google-runtime-member-string-references.rst +++ /dev/null @@ -1,25 +0,0 @@ -.. title:: clang-tidy - google-runtime-member-string-references - -google-runtime-member-string-references -======================================= - -Finds members of type ``const string&``. - -const string reference members are generally considered unsafe as they can be -created from a temporary quite easily. - -.. code-block:: c++ - - struct S { - S(const string &Str) : Str(Str) {} - const string &Str; - }; - S instance("string"); - -In the constructor call a string temporary is created from ``const char *`` and -destroyed immediately after the call. This leaves around a dangling reference. - -This check emit warnings for both ``std::string`` and ``::string`` const -reference members. - -Corresponding cpplint.py check name: `runtime/member_string_reference`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index cb1ef44c766..1551d36754f 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -110,7 +110,6 @@ Clang-Tidy Checks google-readability-redundant-smartptr-get (redirects to readability-redundant-smartptr-get) <google-readability-redundant-smartptr-get> google-readability-todo google-runtime-int - google-runtime-member-string-references google-runtime-operator google-runtime-references hicpp-avoid-goto diff --git a/clang-tools-extra/test/clang-tidy/google-runtime-member-string-references.cpp b/clang-tools-extra/test/clang-tidy/google-runtime-member-string-references.cpp deleted file mode 100644 index 64553c27f79..00000000000 --- a/clang-tools-extra/test/clang-tidy/google-runtime-member-string-references.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// RUN: %check_clang_tidy %s google-runtime-member-string-references %t - -namespace std { -template<typename T> - class basic_string {}; - -typedef basic_string<char> string; -} - -class string {}; - - -struct A { - const std::string &s; -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous; it is much better to use alternatives, such as pointers or simple constants [google-runtime-member-string-references] -}; - -struct B { - std::string &s; -}; - -struct C { - const std::string s; -}; - -template <typename T> -struct D { - D(); - const T &s; - const std::string &s2; -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous -}; - -D<std::string> d; - -struct AA { - const string &s; -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous -}; - -struct BB { - string &s; -}; - -struct CC { - const string s; -}; - -D<string> dd; |

