Author: alexfh Date: Mon Sep 14 11:51:52 2015 New Revision: 247578 URL: http://llvm.org/viewvc/llvm-project?rev=247578&view=rev Log: [clang-tidy] misc-sizeof-container: remove fix-it hints
This turned out to be a rather noisy check, so automated fixes will only do harm. Remove them completely. Modified: clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp Modified: 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=247578&r1=247577&r2=247578&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp Mon Sep 14 11:51:52 2015 @@ -16,21 +16,6 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace { - -bool needsParens(const Expr *E) { - E = E->IgnoreImpCasts(); - if (isa<BinaryOperator>(E) || isa<ConditionalOperator>(E)) - return true; - if (const auto *Op = dyn_cast<CXXOperatorCallExpr>(E)) { - return Op->getNumArgs() == 2 && Op->getOperator() != OO_Call && - Op->getOperator() != OO_Subscript; - } - return false; -} - -} // anonymous namespace - void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( expr(unless(isInTemplateInstantiation()), @@ -52,31 +37,9 @@ void SizeofContainerCheck::check(const M const auto *SizeOf = Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>("sizeof"); - SourceLocation SizeOfLoc = SizeOf->getLocStart(); - auto Diag = diag(SizeOfLoc, "sizeof() doesn't return the size of the " - "container; did you mean .size()?"); - - // Don't generate fixes for macros. - if (SizeOfLoc.isMacroID()) - return; - - SourceLocation RParenLoc = SizeOf->getRParenLoc(); - - // sizeof argument is wrapped in a single ParenExpr. - const auto *Arg = cast<ParenExpr>(SizeOf->getArgumentExpr()); - - if (needsParens(Arg->getSubExpr())) { - Diag << FixItHint::CreateRemoval( - CharSourceRange::getTokenRange(SizeOfLoc, SizeOfLoc)) - << FixItHint::CreateInsertion(RParenLoc.getLocWithOffset(1), - ".size()"); - } else { - Diag << FixItHint::CreateRemoval( - CharSourceRange::getTokenRange(SizeOfLoc, Arg->getLParen())) - << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(RParenLoc, RParenLoc), - ".size()"); - } + auto Diag = + diag(SizeOf->getLocStart(), "sizeof() doesn't return the size of the " + "container; did you mean .size()?"); } } // namespace tidy Modified: 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=247578&r1=247577&r2=247578&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp Mon Sep 14 11:51:52 2015 @@ -65,19 +65,14 @@ void f() { 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-FIXES: int a = 42 + s1.size(); a = 123 * sizeof(s2); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: sizeof() doesn't return the size -// CHECK-FIXES: a = 123 * s2.size(); a = 45 + sizeof(s2 + "asdf"); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: sizeof() doesn't return the size -// CHECK-FIXES: a = 45 + (s2 + "asdf").size(); a = sizeof(v); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: sizeof() doesn't return the size -// CHECK-FIXES: a = v.size(); a = sizeof(std::vector<int>{}); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: sizeof() doesn't return the size -// CHECK-FIXES: a = std::vector<int>{}.size(); a = sizeof(a); a = sizeof(int); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits