void UseUsingCheck::check(const MatchFinder::MatchResult &Result) { const auto *MatchedDecl = Result.Nodes.getNodeAs<TypedefDecl>("typedef"); if (MatchedDecl->getLocation().isInvalid()) return; auto &Context = *Result.Context; auto &SM = *Result.SourceManager; SourceLocation StartLoc = MatchedDecl->getBeginLoc(); if (StartLoc.isMacroID() && IgnoreMacros) return; auto Diag = diag(StartLoc, "use 'using' instead of 'typedef'"); // 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(printPolicy)); } }
void UseUsingCheck::check(const MatchFinder::MatchResult &Result) { const auto *MatchedDecl = Result.Nodes.getNodeAs<TypedefDecl>("typedef"); if (MatchedDecl->getLocation().isInvalid()) return; auto &Context = *Result.Context; auto &SM = *Result.SourceManager; auto Diag = diag(MatchedDecl->getLocStart(), "use 'using' instead of 'typedef'"); if (MatchedDecl->getLocStart().isMacroID()) { return; } SourceRange RemovalRange; if (CheckRemoval(SM, MatchedDecl->getLocStart(), MatchedDecl->getLocEnd(), Context, RemovalRange)) { Diag << FixItHint::CreateReplacement( MatchedDecl->getSourceRange(), "using " + MatchedDecl->getNameAsString() + " = " + MatchedDecl->getUnderlyingType().getAsString(getLangOpts())); } }