return;
}
- const Decl *DeclCtx = Result.Nodes.getNodeAs<Decl>("dc");
+ const auto *DeclCtx = Result.Nodes.getNodeAs<Decl>("dc");
assert(DeclCtx && "Empty decl context.");
replaceQualifiedSymbolInDeclContext(Result, DeclCtx->getDeclContext(), Start,
End, FromDecl);
bool applyAllReplacements(const std::vector<tooling::Replacement> &Replaces,
Rewriter &Rewrite) {
bool Result = true;
- for (std::vector<tooling::Replacement>::const_iterator I = Replaces.begin(),
- E = Replaces.end();
- I != E; ++I) {
+ for (auto I = Replaces.begin(), E = Replaces.end(); I != E; ++I) {
if (I->isApplicable()) {
Result = I->apply(Rewrite) && Result;
} else {
bool writeFiles(const clang::Rewriter &Rewrites) {
- for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(),
- BufferE = Rewrites.buffer_end();
+ for (auto BufferI = Rewrites.buffer_begin(), BufferE = Rewrites.buffer_end();
BufferI != BufferE; ++BufferI) {
StringRef FileName =
Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName();
}
Finder.matchAST(AST->getASTContext());
- for (std::vector<BoundNodes>::iterator MI = Matches.begin(),
- ME = Matches.end();
- MI != ME; ++MI) {
+ for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) {
OS << "\nMatch #" << ++MatchCount << ":\n\n";
- for (BoundNodes::IDToNodeMap::const_iterator BI = MI->getMap().begin(),
- BE = MI->getMap().end();
- BI != BE; ++BI) {
+ for (auto BI = MI->getMap().begin(), BE = MI->getMap().end(); BI != BE;
+ ++BI) {
switch (QS.OutKind) {
case OK_Diag: {
clang::SourceRange R = BI->second.getSourceRange();
std::vector<MatcherCompletion> Comps = Parser::completeExpression(
StringRef(Begin, End - Begin), CompletionPos - Begin, nullptr,
&QS.NamedValues);
- for (std::vector<MatcherCompletion>::iterator I = Comps.begin(),
- E = Comps.end();
- I != E; ++I) {
+ for (auto I = Comps.begin(), E = Comps.end(); I != E; ++I) {
Completions.push_back(LineEditor::Completion(I->TypedText, I->MatcherDecl));
}
return QueryRef();
QuerySession QS(ASTs);
if (!Commands.empty()) {
- for (cl::list<std::string>::iterator I = Commands.begin(),
- E = Commands.end();
- I != E; ++I) {
+ for (auto I = Commands.begin(), E = Commands.end(); I != E; ++I) {
QueryRef Q = QueryParser::parse(*I, QS);
if (!Q->run(llvm::outs(), QS))
return 1;
}
} else if (!CommandFiles.empty()) {
- for (cl::list<std::string>::iterator I = CommandFiles.begin(),
- E = CommandFiles.end();
- I != E; ++I) {
+ for (auto I = CommandFiles.begin(), E = CommandFiles.end(); I != E; ++I) {
std::ifstream Input(I->c_str());
if (!Input.is_open()) {
llvm::errs() << argv[0] << ": cannot open " << *I << "\n";
// Add all fields between current field up until the next intializer.
for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
- if (const T *D = dyn_cast<T>(*Decl)) {
+ if (const auto *D = dyn_cast<T>(*Decl)) {
if (DeclsToInit.count(D) > 0)
Insertions.back().Initializers.emplace_back(getName(D));
}
// Add remaining decls that require initialization.
for (; Decl != std::end(OrderedDecls); ++Decl) {
- if (const T *D = dyn_cast<T>(*Decl)) {
+ if (const auto *D = dyn_cast<T>(*Decl)) {
if (DeclsToInit.count(D) > 0)
Insertions.back().Initializers.emplace_back(getName(D));
}
void SpecialMemberFunctionsCheck::check(
const MatchFinder::MatchResult &Result) {
- const CXXRecordDecl *MatchedDecl =
- Result.Nodes.getNodeAs<CXXRecordDecl>("class-def");
+ const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXRecordDecl>("class-def");
if (!MatchedDecl)
return;
}
void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
- const CXXConstructorDecl *Ctor =
- Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
+ const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
// Do not be confused: isExplicit means 'explicit' keyword is present,
// isImplicit means that it's a compiler-generated constructor.
if (Ctor->isOutOfLine() || Ctor->isImplicit() || Ctor->isDeleted() ||
if (!Function->isCanonicalDecl())
return;
- if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
+ if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
// Don't warn on implementations of an interface using references.
if (Method->begin_overridden_methods() != Method->end_overridden_methods())
return;
}
void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) {
- const VarDecl *VD = Result.Nodes.getNodeAs<VarDecl>("variable");
+ const auto *VD = Result.Nodes.getNodeAs<VarDecl>("variable");
auto Diag = diag(VD->getLocation(),
"twine variables are prone to use-after-free bugs");
}
void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) {
- const Expr *E = Result.Nodes.getNodeAs<Expr>("expr");
+ const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
if (const auto *Call = dyn_cast<CallExpr>(E)) {
const FunctionDecl *Callee = Call->getDirectCallee();
if (!Callee)
// Get the FunctionDecl and FunctionTemplateDecl containing the function
// parameter.
- const FunctionDecl *FuncForParam =
- dyn_cast<FunctionDecl>(ParmVar->getDeclContext());
+ const auto *FuncForParam = dyn_cast<FunctionDecl>(ParmVar->getDeclContext());
if (!FuncForParam)
return;
const FunctionTemplateDecl *FuncTemplate =
auto Parents = Result.Context->getParents(*S);
if (Parents.empty())
return nullptr;
- const Stmt *Parent = Parents[0].get<Stmt>();
+ const auto *Parent = Parents[0].get<Stmt>();
if (!Parent)
return nullptr;
const Stmt *Prev = nullptr;
if (CheckAnonymousTemporaries) {
bool emit = false;
auto *currentSubExpr = subExpr->IgnoreImpCasts();
- const DeclRefExpr *variableReference =
- dyn_cast<DeclRefExpr>(currentSubExpr);
- const CXXConstructExpr *constructorCall =
- dyn_cast<CXXConstructExpr>(currentSubExpr);
+ const auto *variableReference = dyn_cast<DeclRefExpr>(currentSubExpr);
+ const auto *constructorCall = dyn_cast<CXXConstructExpr>(currentSubExpr);
// If we have a DeclRefExpr, we flag for emitting a diagnosis message in
// case the referenced variable is neither a function parameter nor a
// variable declared in the catch statement.
AST_MATCHER(Type, sugaredNullptrType) {
const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
- if (const BuiltinType *BT = dyn_cast<BuiltinType>(DesugaredType))
+ if (const auto *BT = dyn_cast<BuiltinType>(DesugaredType))
return BT->getKind() == BuiltinType::NullPtr;
return false;
}
// Only VisitStmt is overridden as we shouldn't find other base AST types
// within a cast expression.
bool VisitStmt(Stmt *S) {
- CastExpr *C = dyn_cast<CastExpr>(S);
+ auto *C = dyn_cast<CastExpr>(S);
// Catch the castExpr inside cxxDefaultArgExpr.
if (auto *E = dyn_cast<CXXDefaultArgExpr>(S))
C = dyn_cast<CastExpr>(E->getExpr());
}
void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
- const FunctionDecl *Method = Result.Nodes.getNodeAs<FunctionDecl>("method");
+ const auto *Method = Result.Nodes.getNodeAs<FunctionDecl>("method");
const SourceManager &Sources = *Result.SourceManager;
assert(Method != nullptr);
void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context);
- const CallExpr *const CE = Result.Nodes.getNodeAs<CallExpr>("CE");
+ const auto *const CE = Result.Nodes.getNodeAs<CallExpr>("CE");
if (!CE->getDirectCallee())
return;
}
bool areParensNeededForStatement(const Stmt *Statement) {
- if (const CXXOperatorCallExpr *OverloadedOperatorCall =
+ if (const auto *OverloadedOperatorCall =
llvm::dyn_cast<CXXOperatorCallExpr>(Statement)) {
return areParensNeededForOverloadedOperator(
OverloadedOperatorCall->getOperator());
}
void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
- const NamespaceDecl *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace");
+ const auto *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace");
const SourceManager &Sources = *Result.SourceManager;
if (!locationsInSameFile(Sources, ND->getLocStart(), ND->getRBraceLoc()))
}
void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
- const NamedDecl *D = Result.Nodes.getNodeAs<NamedDecl>("Decl");
+ const auto *D = Result.Nodes.getNodeAs<NamedDecl>("Decl");
const auto *Prev = D->getPreviousDecl();
if (!Prev)
return;
bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr;
bool IsMemberExpr = Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr;
- const Expr *GetCall = Result.Nodes.getNodeAs<Expr>("redundant_get");
- const Expr *Smartptr = Result.Nodes.getNodeAs<Expr>("smart_pointer");
+ const auto *GetCall = Result.Nodes.getNodeAs<Expr>("redundant_get");
+ const auto *Smartptr = Result.Nodes.getNodeAs<Expr>("smart_pointer");
if (IsPtrToPtr && IsMemberExpr) {
// Ignore this case (eg. Foo->get()->DoSomething());
return;
}
- const NamedDecl *ND = Result.Nodes.getNodeAs<NamedDecl>("decl");
+ const auto *ND = Result.Nodes.getNodeAs<NamedDecl>("decl");
assert(ND && "Matched declaration must be a NamedDecl!");
const SourceManager *SM = Result.SourceManager;
ModuleMapHeadersSet.insert(ModularizeUtilities::getCanonicalPath(
Header.Entry->getName()));
- for (Module::submodule_const_iterator MI = Mod.submodule_begin(),
- MIEnd = Mod.submodule_end();
- MI != MIEnd; ++MI)
+ for (auto MI = Mod.submodule_begin(), MIEnd = Mod.submodule_end();
+ MI != MIEnd; ++MI)
collectModuleHeaders(**MI);
return true;
const unsigned IncludedFlagsBitmask = options::CC1Option;
unsigned MissingArgIndex, MissingArgCount;
SmallVector<const char *, 256> Argv;
- for (CommandLineArguments::const_iterator I = CLArgs.begin(),
- E = CLArgs.end();
- I != E; ++I)
+ for (auto I = CLArgs.begin(), E = CLArgs.end(); I != E; ++I)
Argv.push_back(I->c_str());
InputArgList Args = Opts->ParseArgs(Argv, MissingArgIndex, MissingArgCount,
IncludedFlagsBitmask);
std::error_code ModularizeUtilities::loadAllHeaderListsAndDependencies() {
typedef std::vector<std::string>::iterator Iter;
// For each input file.
- for (Iter I = InputFilePaths.begin(), E = InputFilePaths.end(); I != E; ++I) {
+ for (auto I = InputFilePaths.begin(), E = InputFilePaths.end(); I != E; ++I) {
llvm::StringRef InputPath = *I;
// If it's a module map.
if (InputPath.endswith(".modulemap")) {
DependentsVector UmbrellaDependents;
// Recursively do submodules.
- for (clang::Module::submodule_const_iterator MI = Mod.submodule_begin(),
- MIEnd = Mod.submodule_end();
- MI != MIEnd; ++MI)
+ for (auto MI = Mod.submodule_begin(), MIEnd = Mod.submodule_end();
+ MI != MIEnd; ++MI)
collectModuleHeaders(**MI);
if (const FileEntry *UmbrellaHeader = Mod.getUmbrellaHeader().Entry) {
}
// Output submodules.
- for (std::vector<Module *>::iterator I = SubModules.begin(),
- E = SubModules.end();
- I != E; ++I) {
+ for (auto I = SubModules.begin(), E = SubModules.end(); I != E; ++I) {
if (!(*I)->output(OS, Indent))
return false;
}
// Output header files.
- for (std::vector<std::string>::iterator I = HeaderFileNames.begin(),
- E = HeaderFileNames.end();
- I != E; ++I) {
+ for (auto I = HeaderFileNames.begin(), E = HeaderFileNames.end(); I != E;
+ ++I) {
OS.indent(Indent);
if (IsProblem || strstr((*I).c_str(), ".inl"))
OS << "exclude header \"" << *I << "\"\n";
// Lookup a sub-module.
Module *Module::findSubModule(llvm::StringRef SubName) {
- for (std::vector<Module *>::iterator I = SubModules.begin(),
- E = SubModules.end();
- I != E; ++I) {
+ for (auto I = SubModules.begin(), E = SubModules.end(); I != E; ++I) {
if ((*I)->Name == SubName)
return *I;
}
DependencyMap &Dependencies, llvm::StringRef HeaderPrefix) {
// Create root module.
- Module *RootModule = new Module(RootModuleName, false);
+ auto *RootModule = new Module(RootModuleName, false);
llvm::SmallString<256> CurrentDirectory;
llvm::sys::fs::current_path(CurrentDirectory);
// Check for the presence of a header inclusion path handle entry.
// Return false if not found.
bool haveInclusionPathHandle(InclusionPathHandle H) {
- for (std::vector<InclusionPathHandle>::iterator
- I = InclusionPathHandles.begin(),
- E = InclusionPathHandles.end();
+ for (auto I = InclusionPathHandles.begin(), E = InclusionPathHandles.end();
I != E; ++I) {
if (*I == H)
return true;
MacroExpansionInstance *
findMacroExpansionInstance(StringHandle MacroExpanded,
PPItemKey &DefinitionLocation) {
- for (std::vector<MacroExpansionInstance>::iterator
- I = MacroExpansionInstances.begin(),
- E = MacroExpansionInstances.end();
+ for (auto I = MacroExpansionInstances.begin(),
+ E = MacroExpansionInstances.end();
I != E; ++I) {
if ((I->MacroExpanded == MacroExpanded) &&
(I->DefinitionLocation == DefinitionLocation)) {
// Check for the presence of a header inclusion path handle entry.
// Return false if not found.
bool haveInclusionPathHandle(InclusionPathHandle H) {
- for (std::vector<InclusionPathHandle>::iterator
- I = InclusionPathHandles.begin(),
- E = InclusionPathHandles.end();
+ for (auto I = InclusionPathHandles.begin(), E = InclusionPathHandles.end();
I != E; ++I) {
if (*I == H)
return true;
// Find a matching condition expansion instance.
ConditionalExpansionInstance *
findConditionalExpansionInstance(clang::PPCallbacks::ConditionValueKind ConditionValue) {
- for (std::vector<ConditionalExpansionInstance>::iterator
- I = ConditionalExpansionInstances.begin(),
- E = ConditionalExpansionInstances.end();
+ for (auto I = ConditionalExpansionInstances.begin(),
+ E = ConditionalExpansionInstances.end();
I != E; ++I) {
if (I->ConditionValue == ConditionValue) {
return &*I; // Found.
HeaderHandle findHeaderHandle(llvm::StringRef HeaderPath) const {
std::string CanonicalPath = getCanonicalPath(HeaderPath);
HeaderHandle H = 0;
- for (std::vector<StringHandle>::const_iterator I = HeaderPaths.begin(),
- E = HeaderPaths.end();
- I != E; ++I, ++H) {
+ for (auto I = HeaderPaths.begin(), E = HeaderPaths.end(); I != E;
+ ++I, ++H) {
if (**I == CanonicalPath)
return H;
}
// Check for presence of header handle in the header stack.
bool isHeaderHandleInStack(HeaderHandle H) const {
- for (std::vector<HeaderHandle>::const_iterator I = HeaderStack.begin(),
- E = HeaderStack.end();
- I != E; ++I) {
+ for (auto I = HeaderStack.begin(), E = HeaderStack.end(); I != E; ++I) {
if (*I == H)
return true;
}
InclusionPathHandle
findInclusionPathHandle(const std::vector<HeaderHandle> &Path) const {
InclusionPathHandle H = 0;
- for (std::vector<HeaderInclusionPath>::const_iterator
- I = InclusionPaths.begin(),
- E = InclusionPaths.end();
- I != E; ++I, ++H) {
+ for (auto I = InclusionPaths.begin(), E = InclusionPaths.end(); I != E;
+ ++I, ++H) {
if (I->Path == Path)
return H;
}
StringHandle MacroName = addString(II->getName());
PPItemKey InstanceKey(PP, MacroName, H, InstanceLoc);
PPItemKey DefinitionKey(PP, MacroName, H, DefinitionLoc);
- MacroExpansionMapIter I = MacroExpansions.find(InstanceKey);
+ auto I = MacroExpansions.find(InstanceKey);
// If existing instance of expansion not found, add one.
if (I == MacroExpansions.end()) {
std::string InstanceSourceLine =
return;
StringHandle ConditionUnexpandedHandle(addString(ConditionUnexpanded));
PPItemKey InstanceKey(PP, ConditionUnexpandedHandle, H, InstanceLoc);
- ConditionalExpansionMapIter I = ConditionalExpansions.find(InstanceKey);
+ auto I = ConditionalExpansions.find(InstanceKey);
// If existing instance of condition not found, add one.
if (I == ConditionalExpansions.end()) {
std::string InstanceSourceLine =
bool reportInconsistentMacros(llvm::raw_ostream &OS) override {
bool ReturnValue = false;
// Walk all the macro expansion trackers in the map.
- for (MacroExpansionMapIter I = MacroExpansions.begin(),
- E = MacroExpansions.end();
- I != E; ++I) {
+ for (auto I = MacroExpansions.begin(), E = MacroExpansions.end(); I != E;
+ ++I) {
const PPItemKey &ItemKey = I->first;
MacroExpansionTracker &MacroExpTracker = I->second;
// If no mismatch (only one instance value) continue.
<< "' has different values in this header, depending on how it was "
"included.\n";
// Walk all the instances.
- for (std::vector<MacroExpansionInstance>::iterator
- IMT = MacroExpTracker.MacroExpansionInstances.begin(),
- EMT = MacroExpTracker.MacroExpansionInstances.end();
+ for (auto IMT = MacroExpTracker.MacroExpansionInstances.begin(),
+ EMT = MacroExpTracker.MacroExpansionInstances.end();
IMT != EMT; ++IMT) {
MacroExpansionInstance &MacroInfo = *IMT;
OS << " '" << *MacroExpTracker.MacroUnexpanded << "' expanded to: '"
<< *MacroInfo.MacroExpanded
<< "' with respect to these inclusion paths:\n";
// Walk all the inclusion path hierarchies.
- for (std::vector<InclusionPathHandle>::iterator
- IIP = MacroInfo.InclusionPathHandles.begin(),
- EIP = MacroInfo.InclusionPathHandles.end();
+ for (auto IIP = MacroInfo.InclusionPathHandles.begin(),
+ EIP = MacroInfo.InclusionPathHandles.end();
IIP != EIP; ++IIP) {
const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP);
- int Count = (int)ip.size();
+ auto Count = (int)ip.size();
for (int Index = 0; Index < Count; ++Index) {
HeaderHandle H = ip[Index];
OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)
bool reportInconsistentConditionals(llvm::raw_ostream &OS) override {
bool ReturnValue = false;
// Walk all the conditional trackers in the map.
- for (ConditionalExpansionMapIter I = ConditionalExpansions.begin(),
- E = ConditionalExpansions.end();
+ for (auto I = ConditionalExpansions.begin(),
+ E = ConditionalExpansions.end();
I != E; ++I) {
const PPItemKey &ItemKey = I->first;
ConditionalTracker &CondTracker = I->second;
<< "' has different values in this header, depending on how it was "
"included.\n";
// Walk all the instances.
- for (std::vector<ConditionalExpansionInstance>::iterator
- IMT = CondTracker.ConditionalExpansionInstances.begin(),
- EMT = CondTracker.ConditionalExpansionInstances.end();
+ for (auto IMT = CondTracker.ConditionalExpansionInstances.begin(),
+ EMT = CondTracker.ConditionalExpansionInstances.end();
IMT != EMT; ++IMT) {
ConditionalExpansionInstance &MacroInfo = *IMT;
OS << " '" << *CondTracker.ConditionUnexpanded << "' expanded to: '"
<< ConditionValueKindStrings[MacroInfo.ConditionValue]
<< "' with respect to these inclusion paths:\n";
// Walk all the inclusion path hierarchies.
- for (std::vector<InclusionPathHandle>::iterator
- IIP = MacroInfo.InclusionPathHandles.begin(),
- EIP = MacroInfo.InclusionPathHandles.end();
+ for (auto IIP = MacroInfo.InclusionPathHandles.begin(),
+ EIP = MacroInfo.InclusionPathHandles.end();
IIP != EIP; ++IIP) {
const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP);
- int Count = (int)ip.size();
+ auto Count = (int)ip.size();
for (int Index = 0; Index < Count; ++Index) {
HeaderHandle H = ip[Index];
OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)
const CallbackCall &Callback = *I;
OS << "- Callback: " << Callback.Name << "\n";
- for (std::vector<Argument>::const_iterator AI = Callback.Arguments.begin(),
- AE = Callback.Arguments.end();
+ for (auto AI = Callback.Arguments.begin(), AE = Callback.Arguments.end();
AI != AE; ++AI) {
const Argument &Arg = *AI;
OS << " " << Arg.Name << ": " << Arg.Value << "\n";
Finder->addMatcher(ast_matchers::varDecl().bind("var"), this);
}
void check(const ast_matchers::MatchFinder::MatchResult &Result) override {
- const VarDecl *Var = Result.Nodes.getNodeAs<VarDecl>("var");
+ const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var");
// Add diagnostics in the wrong order.
diag(Var->getLocation(), "variable");
diag(Var->getTypeSpecStartLoc(), "type specifier");
if (!Aliaser)
Aliaser.reset(new NamespaceAliaser(*Result.SourceManager));
- const CallExpr *Call =
- Result.Nodes.getNodeAs<CallExpr>("foo");
+ const auto *Call = Result.Nodes.getNodeAs<CallExpr>("foo");
assert(Call != nullptr && "Did not find node \"foo\"");
auto Hint = Aliaser->createAlias(*Result.Context, *Call, "::foo::bar",
{"b", "some_alias"});
if (!Inserter)
Inserter.reset(new UsingInserter(*Result.SourceManager));
- const clang::CallExpr *Call =
- Result.Nodes.getNodeAs<clang::CallExpr>("foo");
+ const auto *Call = Result.Nodes.getNodeAs<clang::CallExpr>("foo");
assert(Call != nullptr && "Did not find node \"foo\"");
auto Hint =
Inserter->createUsingDeclaration(*Result.Context, *Call, "::foo::func");