diff options
author | Krystyna Gajczyk <krystyna.gajczyk@gmail.com> | 2017-04-02 19:12:20 +0000 |
---|---|---|
committer | Krystyna Gajczyk <krystyna.gajczyk@gmail.com> | 2017-04-02 19:12:20 +0000 |
commit | 3a42e73c3fe6ee69bd70241659fd36ae4335ad0a (patch) | |
tree | f6ea694f0214196e6f0ea92dbc5bb35721d561ee /clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | |
parent | 70e4f434ae2da6c178460f920de9315dc435d669 (diff) | |
download | llvm-3a42e73c3fe6ee69bd70241659fd36ae4335ad0a.zip llvm-3a42e73c3fe6ee69bd70241659fd36ae4335ad0a.tar.gz llvm-3a42e73c3fe6ee69bd70241659fd36ae4335ad0a.tar.bz2 |
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
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
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)); } } |