From 3a42e73c3fe6ee69bd70241659fd36ae4335ad0a Mon Sep 17 00:00:00 2001 From: Krystyna Gajczyk Date: Sun, 2 Apr 2017 19:12:20 +0000 Subject: Fixes for modernize-use-using check: - removed unnessacary namespaces - added option to print warning in macros - no fix for typedef with array - removed "void" word from functions with 0 parameters Differential Revision: https://reviews.llvm.org/D29262 llvm-svn: 299340 --- .../clang-tidy/modernize/UseUsingCheck.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp') diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index 77b3dc9..fc9dc76 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp @@ -17,6 +17,10 @@ namespace clang { namespace tidy { namespace modernize { +UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), + IgnoreMacros(Options.get("IgnoreMacros", true)) {} + void UseUsingCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus11) return; @@ -79,18 +83,28 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) { auto &Context = *Result.Context; auto &SM = *Result.SourceManager; + SourceLocation StartLoc = MatchedDecl->getLocStart(); + + if (StartLoc.isMacroID() && IgnoreMacros) + return; + auto Diag = - diag(MatchedDecl->getLocStart(), "use 'using' instead of 'typedef'"); + diag(StartLoc, "use 'using' instead of 'typedef'"); - SourceLocation StartLoc = MatchedDecl->getLocStart(); - if (StartLoc.isMacroID()) + // do not fix if there is macro or array + if (MatchedDecl->getUnderlyingType()->isArrayType() || StartLoc.isMacroID()) return; if (CheckRemoval(SM, StartLoc, Context)) { + auto printPolicy = PrintingPolicy(getLangOpts()); + printPolicy.SuppressScope = true; + printPolicy.ConstantArraySizeAsWritten = true; + printPolicy.UseVoidForZeroParams = false; + Diag << FixItHint::CreateReplacement( MatchedDecl->getSourceRange(), "using " + MatchedDecl->getNameAsString() + " = " + - MatchedDecl->getUnderlyingType().getAsString(getLangOpts())); + MatchedDecl->getUnderlyingType().getAsString(printPolicy)); } } -- cgit v1.1