Author: alexfh Date: Thu Mar 15 01:26:47 2018 New Revision: 327608 URL: http://llvm.org/viewvc/llvm-project?rev=327608&view=rev Log: [clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-container
Added: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp - copied, changed from r327607, clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h - copied, changed from r327607, clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-container.rst - copied, changed from r327607, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-container.cpp - copied, changed from r327607, clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp Removed: clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327608&r1=327607&r2=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Mar 15 01:26:47 2018 @@ -28,6 +28,7 @@ #include "MisplacedWideningCastCheck.h" #include "MoveForwardingReferenceCheck.h" #include "MultipleStatementMacroCheck.h" +#include "SizeofContainerCheck.h" #include "SizeofExpressionCheck.h" #include "StringConstructorCheck.h" #include "StringIntegerAssignmentCheck.h" @@ -87,6 +88,8 @@ public: "bugprone-move-forwarding-reference"); CheckFactories.registerCheck<MultipleStatementMacroCheck>( "bugprone-multiple-statement-macro"); + CheckFactories.registerCheck<SizeofContainerCheck>( + "bugprone-sizeof-container"); CheckFactories.registerCheck<SizeofExpressionCheck>( "bugprone-sizeof-expression"); CheckFactories.registerCheck<StringConstructorCheck>( Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327608&r1=327607&r2=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Mar 15 01:26:47 2018 @@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModul MisplacedWideningCastCheck.cpp MoveForwardingReferenceCheck.cpp MultipleStatementMacroCheck.cpp + SizeofContainerCheck.cpp SizeofExpressionCheck.cpp StringConstructorCheck.cpp StringIntegerAssignmentCheck.cpp Copied: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp (from r327607, clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp&r1=327607&r2=327608&rev=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp Thu Mar 15 01:26:47 2018 @@ -15,7 +15,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace bugprone { void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( @@ -44,6 +44,6 @@ void SizeofContainerCheck::check(const M "container; did you mean .size()?"); } -} // namespace misc +} // namespace bugprone } // namespace tidy } // namespace clang Copied: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h (from r327607, clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h?p2=clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h&r1=327607&r2=327608&rev=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h Thu Mar 15 01:26:47 2018 @@ -7,20 +7,20 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIZEOFCONTAINERCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIZEOFCONTAINERCHECK_H #include "../ClangTidy.h" namespace clang { namespace tidy { -namespace misc { +namespace bugprone { /// Find usages of sizeof on expressions of STL container types. Most likely the /// user wanted to use `.size()` instead. /// /// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/misc-sizeof-container.html +/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-container.html class SizeofContainerCheck : public ClangTidyCheck { public: SizeofContainerCheck(StringRef Name, ClangTidyContext *Context) @@ -29,8 +29,8 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; -} // namespace misc +} // namespace bugprone } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIZEOFCONTAINERCHECK_H Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=327608&r1=327607&r2=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Thu Mar 15 01:26:47 2018 @@ -8,7 +8,6 @@ add_clang_library(clangTidyMiscModule NewDeleteOverloadsCheck.cpp NonCopyableObjects.cpp RedundantExpressionCheck.cpp - SizeofContainerCheck.cpp StaticAssertCheck.cpp ThrowByValueCatchByReferenceCheck.cpp UniqueptrResetReleaseCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=327608&r1=327607&r2=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Thu Mar 15 01:26:47 2018 @@ -15,7 +15,6 @@ #include "NewDeleteOverloadsCheck.h" #include "NonCopyableObjects.h" #include "RedundantExpressionCheck.h" -#include "SizeofContainerCheck.h" #include "StaticAssertCheck.h" #include "ThrowByValueCatchByReferenceCheck.h" #include "UnconventionalAssignOperatorCheck.h" @@ -43,7 +42,6 @@ public: "misc-non-copyable-objects"); CheckFactories.registerCheck<RedundantExpressionCheck>( "misc-redundant-expression"); - CheckFactories.registerCheck<SizeofContainerCheck>("misc-sizeof-container"); CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert"); CheckFactories.registerCheck<ThrowByValueCatchByReferenceCheck>( "misc-throw-by-value-catch-by-reference"); Removed: clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp?rev=327607&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp (removed) @@ -1,49 +0,0 @@ -//===--- SizeofContainerCheck.cpp - clang-tidy-----------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "SizeofContainerCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher( - expr(unless(isInTemplateInstantiation()), - expr(sizeOfExpr(has(ignoringParenImpCasts( - expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl( - matchesName("^(::std::|::string)"), - unless(matchesName("^::std::(bitset|array)$")), - hasMethod(cxxMethodDecl(hasName("size"), isPublic(), - isConst()))))))))))) - .bind("sizeof"), - // Ignore ARRAYSIZE(<array of containers>) pattern. - unless(hasAncestor(binaryOperator( - anyOf(hasOperatorName("/"), hasOperatorName("%")), - hasLHS(ignoringParenCasts(sizeOfExpr(expr()))), - hasRHS(ignoringParenCasts(equalsBoundNode("sizeof"))))))), - this); -} - -void SizeofContainerCheck::check(const MatchFinder::MatchResult &Result) { - const auto *SizeOf = - Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>("sizeof"); - - auto Diag = - diag(SizeOf->getLocStart(), "sizeof() doesn't return the size of the " - "container; did you mean .size()?"); -} - -} // namespace misc -} // namespace tidy -} // namespace clang Removed: clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h?rev=327607&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h (removed) @@ -1,36 +0,0 @@ -//===--- SizeofContainerCheck.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_MISC_SIZEOF_CONTAINER_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace misc { - -/// Find usages of sizeof on expressions of STL container types. Most likely the -/// user wanted to use `.size()` instead. -/// -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/misc-sizeof-container.html -class SizeofContainerCheck : public ClangTidyCheck { -public: - SizeofContainerCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=327608&r1=327607&r2=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original) +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Mar 15 01:26:47 2018 @@ -137,6 +137,9 @@ Improvements to clang-tidy - The 'misc-misplaced-widening-cast' check was renamed to `bugprone-misplaced-widening-cast <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-misplaced-widening-cast.html>`_ +- The 'misc-sizeof-container' check was renamed to `bugprone-sizeof-container + <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-container.html>`_ + - The 'misc-sizeof-expression' check was renamed to `bugprone-sizeof-expression <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-expression.html>`_ Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-container.rst (from r327607, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-container.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-container.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst&r1=327607&r2=327608&rev=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-container.rst Thu Mar 15 01:26:47 2018 @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-sizeof-container +.. title:: clang-tidy - bugprone-sizeof-container -misc-sizeof-container -===================== +bugprone-sizeof-container +========================= The check finds usages of ``sizeof`` on expressions of STL container types. Most likely the user wanted to use ``.size()`` instead. Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=327608&r1=327607&r2=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Mar 15 01:26:47 2018 @@ -36,6 +36,7 @@ Clang-Tidy Checks bugprone-misplaced-widening-cast bugprone-move-forwarding-reference bugprone-multiple-statement-macro + bugprone-sizeof-container bugprone-sizeof-expression bugprone-string-constructor bugprone-string-integer-assignment @@ -146,7 +147,6 @@ Clang-Tidy Checks misc-new-delete-overloads misc-non-copyable-objects misc-redundant-expression - misc-sizeof-container misc-static-assert misc-throw-by-value-catch-by-reference misc-unconventional-assign-operator Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst?rev=327607&view=auto ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst (removed) @@ -1,26 +0,0 @@ -.. title:: clang-tidy - misc-sizeof-container - -misc-sizeof-container -===================== - -The check finds usages of ``sizeof`` on expressions of STL container types. Most -likely the user wanted to use ``.size()`` instead. - -All class/struct types declared in namespace ``std::`` having a const ``size()`` -method are considered containers, with the exception of ``std::bitset`` and -``std::array``. - -Examples: - -.. code-block:: c++ - - std::string s; - int a = 47 + sizeof(s); // warning: sizeof() doesn't return the size of the container. Did you mean .size()? - - int b = sizeof(std::string); // no warning, probably intended. - - std::string array_of_strings[10]; - int c = sizeof(array_of_strings) / sizeof(array_of_strings[0]); // no warning, definitely intended. - - std::array<int, 3> std_array; - int d = sizeof(std_array); // no warning, probably intended. Copied: clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-container.cpp (from r327607, clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-container.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-container.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp&r1=327607&r2=327608&rev=327608&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-container.cpp Thu Mar 15 01:26:47 2018 @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-sizeof-container %t -- -- -std=c++11 -target x86_64-unknown-unknown +// RUN: %check_clang_tidy %s bugprone-sizeof-container %t -- -- -std=c++11 -target x86_64-unknown-unknown namespace std { @@ -64,7 +64,7 @@ void f() { std::vector<int> v; int a = 42 + sizeof(s1); -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: sizeof() doesn't return the size of the container; did you mean .size()? [misc-sizeof-container] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: sizeof() doesn't return the size of the container; did you mean .size()? [bugprone-sizeof-container] a = 123 * sizeof(s2); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: sizeof() doesn't return the size a = 45 + sizeof(s2 + "asdf"); Removed: clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp?rev=327607&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp (removed) @@ -1,103 +0,0 @@ -// RUN: %check_clang_tidy %s misc-sizeof-container %t -- -- -std=c++11 -target x86_64-unknown-unknown - -namespace std { - -typedef unsigned int size_t; - -template <typename T> -struct basic_string { - size_t size() const; -}; - -template <typename T> -basic_string<T> operator+(const basic_string<T> &, const T *); - -typedef basic_string<char> string; - -template <typename T> -struct vector { - size_t size() const; -}; - -// std::bitset<> is not a container. sizeof() is reasonable for it. -template <size_t N> -struct bitset { - size_t size() const; -}; - -// std::array<> is, well, an array. sizeof() is reasonable for it. -template <typename T, size_t N> -struct array { - size_t size() const; -}; - -class fake_container1 { - size_t size() const; // non-public -}; - -struct fake_container2 { - size_t size(); // non-const -}; - -} - -using std::size_t; - -#define ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) - -#define ARRAYSIZE2(a) \ - (((sizeof(a)) / (sizeof(*(a)))) / static_cast<size_t>(!((sizeof(a)) % (sizeof(*(a)))))) - -struct string { - std::size_t size() const; -}; - -template<typename T> -void g(T t) { - (void)sizeof(t); -} - -void f() { - string s1; - std::string s2; - std::vector<int> v; - - int a = 42 + sizeof(s1); -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: sizeof() doesn't return the size of the container; did you mean .size()? [misc-sizeof-container] - a = 123 * sizeof(s2); -// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: sizeof() doesn't return the size - a = 45 + sizeof(s2 + "asdf"); -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: sizeof() doesn't return the size - a = sizeof(v); -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: sizeof() doesn't return the size - a = sizeof(std::vector<int>{}); -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: sizeof() doesn't return the size - - a = sizeof(a); - a = sizeof(int); - a = sizeof(std::string); - a = sizeof(std::vector<int>); - - g(s1); - g(s2); - g(v); - - std::fake_container1 fake1; - std::fake_container2 fake2; - std::bitset<7> std_bitset; - std::array<int, 3> std_array; - - a = sizeof(fake1); - a = sizeof(fake2); - a = sizeof(std_bitset); - a = sizeof(std_array); - - - std::string arr[3]; - a = ARRAYSIZE(arr); - a = ARRAYSIZE2(arr); - a = sizeof(arr) / sizeof(arr[0]); - - (void)a; -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits