Index: lib/AST/Decl.cpp =================================================================== --- lib/AST/Decl.cpp +++ lib/AST/Decl.cpp @@ -207,13 +207,13 @@ // If we're ultimately computing the visibility of a type, look for // a 'type_visibility' attribute before looking for 'visibility'. if (kind == NamedDecl::VisibilityForType) { - if (const TypeVisibilityAttr *A = D->getAttr()) { + if (const auto *A = D->getAttr()) { return getVisibilityFromAttr(A); } } // If this declaration has an explicit visibility attribute, use it. - if (const VisibilityAttr *A = D->getAttr()) { + if (const auto *A = D->getAttr()) { return getVisibilityFromAttr(A); } @@ -252,8 +252,7 @@ // template class A { ... }; // We have to be careful here, though, because we can be dealing with // dependent types. - if (const NonTypeTemplateParmDecl *NTTP = - dyn_cast(P)) { + if (const auto *NTTP = dyn_cast(P)) { // Handle the non-pack case first. if (!NTTP->isExpandedParameterPack()) { if (!NTTP->getType()->isDependentType()) { @@ -273,7 +272,7 @@ // Template template parameters can be restricted by their // template parameters, recursively. - const TemplateTemplateParmDecl *TTP = cast(P); + const auto *TTP = cast(P); // Handle the non-pack case first. if (!TTP->isExpandedParameterPack()) { @@ -329,7 +328,7 @@ continue; case TemplateArgument::Declaration: - if (NamedDecl *ND = dyn_cast(Arg.getAsDecl())) { + if (const auto *ND = dyn_cast(Arg.getAsDecl())) { assert(!usesTypeVisibility(ND)); LV.merge(getLVForDecl(ND, computation)); } @@ -541,7 +540,7 @@ if (!Opts.CPlusPlus || !Opts.InlineVisibilityHidden) return false; - const FunctionDecl *FD = dyn_cast(D); + const auto *FD = dyn_cast(D); if (!FD) return false; @@ -569,7 +568,7 @@ } static bool isSingleLineLanguageLinkage(const Decl &D) { - if (const LinkageSpecDecl *SD = dyn_cast(D.getDeclContext())) + if (const auto *SD = dyn_cast(D.getDeclContext())) if (!SD->hasBraces()) return true; return false; @@ -587,7 +586,7 @@ // - an object, reference, function or function template that is // explicitly declared static; or, // (This bullet corresponds to C99 6.2.2p3.) - if (const VarDecl *Var = dyn_cast(D)) { + if (const auto *Var = dyn_cast(D)) { // Explicitly declared static. if (Var->getStorageClass() == SC_Static) return LinkageInfo::internal(); @@ -634,8 +633,8 @@ assert(!isa(D) && "Didn't expect a FieldDecl!"); if (D->isInAnonymousNamespace()) { - const VarDecl *Var = dyn_cast(D); - const FunctionDecl *Func = dyn_cast(D); + const auto *Var = dyn_cast(D); + const auto *Func = dyn_cast(D); if ((!Var || !isFirstInExternCContext(Var)) && (!Func || !isFirstInExternCContext(Func))) return LinkageInfo::uniqueExternal(); @@ -658,7 +657,7 @@ for (const DeclContext *DC = D->getDeclContext(); !isa(DC); DC = DC->getParent()) { - const NamespaceDecl *ND = dyn_cast(DC); + const auto *ND = dyn_cast(DC); if (!ND) continue; if (Optional Vis = getExplicitVisibility(ND, computation)) { LV.mergeVisibility(*Vis, true); @@ -692,7 +691,7 @@ // name of // // - an object or reference, unless it has internal linkage; or - if (const VarDecl *Var = dyn_cast(D)) { + if (const auto *Var = dyn_cast(D)) { // GCC applies the following optimization to variables and static // data members, but not to functions: // @@ -732,13 +731,12 @@ // As per function and class template specializations (below), // consider LV for the template and template arguments. We're at file // scope, so we do not need to worry about nested specializations. - if (const VarTemplateSpecializationDecl *spec - = dyn_cast(Var)) { + if (const auto *spec = dyn_cast(Var)) { mergeTemplateLV(LV, spec, computation); } // - a function, unless it has internal linkage; or - } else if (const FunctionDecl *Function = dyn_cast(D)) { + } else if (const auto *Function = dyn_cast(D)) { // In theory, we can modify the function's LV by the LV of its // type unless it has C linkage (see comment above about variables // for justification). In practice, GCC doesn't do this, so it's @@ -785,7 +783,7 @@ // - a named enumeration (7.2), or an unnamed enumeration // defined in a typedef declaration in which the enumeration // has the typedef name for linkage purposes (7.1.3); or - } else if (const TagDecl *Tag = dyn_cast(D)) { + } else if (const auto *Tag = dyn_cast(D)) { // Unnamed tags have no linkage. if (!Tag->hasNameForLinkage()) return LinkageInfo::none(); @@ -793,8 +791,7 @@ // If this is a class template specialization, consider the // linkage of the template and template arguments. We're at file // scope, so we do not need to worry about nested specializations. - if (const ClassTemplateSpecializationDecl *spec - = dyn_cast(Tag)) { + if (const auto *spec = dyn_cast(Tag)) { mergeTemplateLV(LV, spec, computation); } @@ -808,7 +805,7 @@ // - a template, unless it is a function template that has // internal linkage (Clause 14); - } else if (const TemplateDecl *temp = dyn_cast(D)) { + } else if (const auto *temp = dyn_cast(D)) { bool considerVisibility = !hasExplicitVisibilityAlready(computation); LinkageInfo tempLV = getLVForTemplateParameterList(temp->getTemplateParameters(), computation); @@ -897,7 +894,7 @@ // Specifically, if this decl exists and has an explicit attribute. const NamedDecl *explicitSpecSuppressor = nullptr; - if (const CXXMethodDecl *MD = dyn_cast(D)) { + if (const auto *MD = dyn_cast(D)) { // If the type of the function uses a type with unique-external // linkage, it's not legally usable from outside this translation unit. // But only look at the type-as-written. If this function has an @@ -928,9 +925,8 @@ explicitSpecSuppressor = MD; } - } else if (const CXXRecordDecl *RD = dyn_cast(D)) { - if (const ClassTemplateSpecializationDecl *spec - = dyn_cast(RD)) { + } else if (const auto *RD = dyn_cast(D)) { + if (const auto *spec = dyn_cast(RD)) { mergeTemplateLV(LV, spec, computation); if (spec->isExplicitSpecialization()) { explicitSpecSuppressor = spec; @@ -945,9 +941,8 @@ } // Static data members. - } else if (const VarDecl *VD = dyn_cast(D)) { - if (const VarTemplateSpecializationDecl *spec - = dyn_cast(VD)) + } else if (const auto *VD = dyn_cast(D)) { + if (const auto *spec = dyn_cast(VD)) mergeTemplateLV(LV, spec, computation); // Modify the variable's linkage by its type, but ignore the @@ -962,7 +957,7 @@ } // Template members. - } else if (const TemplateDecl *temp = dyn_cast(D)) { + } else if (const auto *temp = dyn_cast(D)) { bool considerVisibility = (!LV.isVisibilityExplicit() && !classLV.isVisibilityExplicit() && @@ -971,8 +966,7 @@ getLVForTemplateParameterList(temp->getTemplateParameters(), computation); LV.mergeMaybeWithVisibility(tempLV, considerVisibility); - if (const RedeclarableTemplateDecl *redeclTemp = - dyn_cast(temp)) { + if (const auto *redeclTemp = dyn_cast(temp)) { if (isExplicitMemberSpecialization(redeclTemp)) { explicitSpecSuppressor = temp->getTemplatedDecl(); } @@ -1048,7 +1042,7 @@ // If this is a member class of a specialization of a class template // and the corresponding decl has explicit visibility, use that. - if (const CXXRecordDecl *RD = dyn_cast(ND)) { + if (const auto *RD = dyn_cast(ND)) { CXXRecordDecl *InstantiatedFrom = RD->getInstantiatedFromMemberClass(); if (InstantiatedFrom) return getVisibilityOf(InstantiatedFrom, kind); @@ -1057,8 +1051,7 @@ // If there wasn't explicit visibility there, and this is a // specialization of a class template, check for visibility // on the pattern. - if (const ClassTemplateSpecializationDecl *spec - = dyn_cast(ND)) + if (const auto *spec = dyn_cast(ND)) return getVisibilityOf(spec->getSpecializedTemplate()->getTemplatedDecl(), kind); @@ -1069,7 +1062,7 @@ return getExplicitVisibilityAux(MostRecent, kind, true); } - if (const VarDecl *Var = dyn_cast(ND)) { + if (const auto *Var = dyn_cast(ND)) { if (Var->isStaticDataMember()) { VarDecl *InstantiatedFrom = Var->getInstantiatedFromStaticDataMember(); if (InstantiatedFrom) @@ -1083,7 +1076,7 @@ return None; } // Also handle function template specializations. - if (const FunctionDecl *fn = dyn_cast(ND)) { + if (const auto *fn = dyn_cast(ND)) { // If the function is a specialization of a template with an // explicit visibility attribute, use that. if (FunctionTemplateSpecializationInfo *templateInfo @@ -1101,7 +1094,7 @@ } // The visibility of a template is stored in the templated decl. - if (const TemplateDecl *TD = dyn_cast(ND)) + if (const auto *TD = dyn_cast(ND)) return getVisibilityOf(TD->getTemplatedDecl(), kind); return None; @@ -1122,7 +1115,7 @@ return getLVForDecl(cast(ContextDecl), computation); } - if (const NamedDecl *ND = dyn_cast(DC)) + if (const auto *ND = dyn_cast(DC)) return getLVForDecl(ND, computation); return LinkageInfo::external(); @@ -1130,7 +1123,7 @@ static LinkageInfo getLVForLocalDecl(const NamedDecl *D, LVComputationKind computation) { - if (const FunctionDecl *Function = dyn_cast(D)) { + if (const auto *Function = dyn_cast(D)) { if (Function->isInAnonymousNamespace() && !Function->isInExternCContext()) return LinkageInfo::uniqueExternal(); @@ -1153,7 +1146,7 @@ return LV; } - if (const VarDecl *Var = dyn_cast(D)) { + if (const auto *Var = dyn_cast(D)) { if (Var->hasExternalStorage()) { if (Var->isInAnonymousNamespace() && !Var->isInExternCContext()) return LinkageInfo::uniqueExternal(); @@ -1189,14 +1182,14 @@ return LinkageInfo::none(); LinkageInfo LV; - if (const BlockDecl *BD = dyn_cast(OuterD)) { + if (const auto *BD = dyn_cast(OuterD)) { if (!BD->getBlockManglingNumber()) return LinkageInfo::none(); LV = getLVForClosure(BD->getDeclContext()->getRedeclContext(), BD->getBlockManglingContextDecl(), computation); } else { - const FunctionDecl *FD = cast(OuterD); + const auto *FD = cast(OuterD); if (!FD->isInlined() && !isTemplateInstantiation(FD->getTemplateSpecializationKind())) return LinkageInfo::none(); @@ -1245,7 +1238,7 @@ return LinkageInfo::external(); case Decl::CXXRecord: { - const CXXRecordDecl *Record = cast(D); + const auto *Record = cast(D); if (Record->isLambda()) { if (!Record->getLambdaManglingNumber()) { // This lambda has no mangling number, so it's internal. @@ -1336,7 +1329,7 @@ // computed also does. NamedDecl *Old = nullptr; for (auto I : D->redecls()) { - NamedDecl *T = cast(I); + auto *T = cast(I); if (T == D) continue; if (!T->isInvalidDecl() && T->hasCachedLinkage()) { @@ -1388,15 +1381,14 @@ for (ContextsTy::reverse_iterator I = Contexts.rbegin(), E = Contexts.rend(); I != E; ++I) { - if (const ClassTemplateSpecializationDecl *Spec - = dyn_cast(*I)) { + if (const auto *Spec = dyn_cast(*I)) { OS << Spec->getName(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateArgs.data(), TemplateArgs.size(), P); - } else if (const NamespaceDecl *ND = dyn_cast(*I)) { + } else if (const auto *ND = dyn_cast(*I)) { if (P.SuppressUnwrittenScope && (ND->isAnonymousNamespace() || ND->isInline())) continue; @@ -1404,12 +1396,12 @@ OS << "(anonymous namespace)"; else OS << *ND; - } else if (const RecordDecl *RD = dyn_cast(*I)) { + } else if (const auto *RD = dyn_cast(*I)) { if (!RD->getIdentifier()) OS << "(anonymous " << RD->getKindName() << ')'; else OS << *RD; - } else if (const FunctionDecl *FD = dyn_cast(*I)) { + } else if (const auto *FD = dyn_cast(*I)) { const FunctionProtoType *FT = nullptr; if (FD->hasWrittenPrototype()) FT = dyn_cast(FD->getType()->castAs()); @@ -1430,7 +1422,7 @@ } } OS << ')'; - } else if (const EnumDecl *ED = dyn_cast(*I)) { + } else if (const auto *ED = dyn_cast(*I)) { // C++ [dcl.enum]p10: Each enum-name and each unscoped // enumerator is declared in the scope that immediately contains // the enum-specifier. Each scoped enumerator is declared in the @@ -1565,10 +1557,10 @@ NamedDecl *NamedDecl::getUnderlyingDeclImpl() { NamedDecl *ND = this; - while (UsingShadowDecl *UD = dyn_cast(ND)) + while (auto *UD = dyn_cast(ND)) ND = UD->getTargetDecl(); - if (ObjCCompatibleAliasDecl *AD = dyn_cast(ND)) + if (auto *AD = dyn_cast(ND)) return AD->getClassInterface(); return ND; @@ -1584,8 +1576,7 @@ if (isa(D) || isa(D) || isa(D)) return true; - if (const CXXMethodDecl *MD = - dyn_cast_or_null(D->getAsFunction())) + if (const auto *MD = dyn_cast_or_null(D->getAsFunction())) return MD->isInstance(); return false; } @@ -1613,7 +1604,7 @@ // Make sure the extended decl info is allocated. if (!hasExtInfo()) { // Save (non-extended) type source info pointer. - TypeSourceInfo *savedTInfo = DeclInfo.get(); + auto *savedTInfo = DeclInfo.get(); // Allocate external info struct. DeclInfo = new (getASTContext()) ExtInfo; // Restore savedTInfo into (extended) decl info. @@ -1644,7 +1635,7 @@ // Make sure the extended decl info is allocated. if (!hasExtInfo()) { // Save (non-extended) type source info pointer. - TypeSourceInfo *savedTInfo = DeclInfo.get(); + auto *savedTInfo = DeclInfo.get(); // Allocate external info struct. DeclInfo = new (getASTContext()) ExtInfo; // Restore savedTInfo into (extended) decl info. @@ -1972,7 +1963,7 @@ VarDecl::DefinitionKind VarDecl::hasDefinition(ASTContext &C) const { DefinitionKind Kind = DeclarationOnly; - + const VarDecl *First = getFirstDecl(); for (auto I : First->redecls()) { Kind = std::max(Kind, I->isThisDeclarationADefinition(C)); @@ -2022,7 +2013,7 @@ } void VarDecl::setInit(Expr *I) { - if (EvaluatedStmt *Eval = Init.dyn_cast()) { + if (auto *Eval = Init.dyn_cast()) { Eval->~EvaluatedStmt(); getASTContext().Deallocate(Eval); } @@ -2061,9 +2052,9 @@ /// form, which contains extra information on the evaluated value of the /// initializer. EvaluatedStmt *VarDecl::ensureEvaluatedStmt() const { - EvaluatedStmt *Eval = Init.dyn_cast(); + auto *Eval = Init.dyn_cast(); if (!Eval) { - Stmt *S = Init.get(); + auto *S = Init.get(); // Note: EvaluatedStmt contains an APValue, which usually holds // resources not allocated from the ASTContext. We need to do some // work to avoid leaking those, but we do so in VarDecl::evaluateValue @@ -2097,7 +2088,7 @@ if (Eval->WasEvaluated) return Eval->Evaluated.isUninit() ? nullptr : &Eval->Evaluated; - const Expr *Init = cast(Eval->Value); + const auto *Init = cast(Eval->Value); assert(!Init->isValueDependent()); if (Eval->IsEvaluating) { @@ -2144,7 +2135,7 @@ // integral constant expression. return Eval->IsICE; - const Expr *Init = cast(Eval->Value); + const auto *Init = cast(Eval->Value); assert(!Init->isValueDependent()); // In C++11, evaluate the initializer to check whether it's a constant @@ -2177,8 +2168,7 @@ } TemplateSpecializationKind VarDecl::getTemplateSpecializationKind() const { - if (const VarTemplateSpecializationDecl *Spec = - dyn_cast(this)) + if (const auto *Spec = dyn_cast(this)) return Spec->getSpecializationKind(); if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) @@ -2188,8 +2178,7 @@ } SourceLocation VarDecl::getPointOfInstantiation() const { - if (const VarTemplateSpecializationDecl *Spec = - dyn_cast(this)) + if (const auto *Spec = dyn_cast(this)) return Spec->getPointOfInstantiation(); if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) @@ -2262,7 +2251,7 @@ QualType ParmVarDecl::getOriginalType() const { TypeSourceInfo *TSI = getTypeSourceInfo(); QualType T = TSI ? TSI->getType() : getType(); - if (const DecayedType *DT = dyn_cast(T)) + if (const auto *DT = dyn_cast(T)) return DT->getOriginalType(); return T; } @@ -2292,9 +2281,9 @@ assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!"); assert(!hasUninstantiatedDefaultArg() && "Default argument is not yet instantiated!"); - + Expr *Arg = getInit(); - if (ExprWithCleanups *E = dyn_cast_or_null(Arg)) + if (auto *E = dyn_cast_or_null(Arg)) return E->getSubExpr(); return Arg; @@ -2337,7 +2326,7 @@ } bool FunctionDecl::isVariadic() const { - if (const FunctionProtoType *FT = getType()->getAs()) + if (const auto *FT = getType()->getAs()) return FT->isVariadic(); return false; } @@ -2398,7 +2387,7 @@ void FunctionDecl::setPure(bool P) { IsPure = P; if (P) - if (CXXRecordDecl *Parent = dyn_cast(getDeclContext())) + if (auto *Parent = dyn_cast(getDeclContext())) Parent->markedVirtualFunctionPure(); } @@ -2453,7 +2442,7 @@ if (!getDeclContext()->getRedeclContext()->isTranslationUnit()) return false; - const FunctionProtoType *proto = getType()->castAs(); + const auto *proto = getType()->castAs(); if (proto->getNumParams() != 2 || proto->isVariadic()) return false; @@ -2482,7 +2471,7 @@ if (!getDeclContext()->getRedeclContext()->isTranslationUnit()) return false; - const FunctionProtoType *FPT = getType()->castAs(); + const auto *FPT = getType()->castAs(); if (FPT->getNumParams() == 0 || FPT->getNumParams() > 2 || FPT->isVariadic()) return false; @@ -2524,7 +2513,7 @@ } bool FunctionDecl::isGlobal() const { - if (const CXXMethodDecl *Method = dyn_cast(this)) + if (const auto *Method = dyn_cast(this)) return Method->isStatic(); if (getCanonicalDecl()->getStorageClass() == SC_Static) @@ -2533,7 +2522,7 @@ for (const DeclContext *DC = getDeclContext(); DC->isNamespace(); DC = DC->getParent()) { - if (const NamespaceDecl *Namespace = cast(DC)) { + if (const auto *Namespace = cast(DC)) { if (!Namespace->getDeclName()) return false; break; @@ -2585,8 +2574,8 @@ ASTContext &Context = getASTContext(); if (Context.getLangOpts().CPlusPlus) { - const LinkageSpecDecl *LinkageDecl = dyn_cast( - getFirstDecl()->getDeclContext()); + const auto *LinkageDecl = + dyn_cast(getFirstDecl()->getDeclContext()); // In C++, the first declaration of a builtin is always inside an implicit // extern "C". // FIXME: A recognised library function may not be directly in an extern "C" @@ -2626,7 +2615,7 @@ /// based on its FunctionType. This is the length of the ParamInfo array /// after it has been created. unsigned FunctionDecl::getNumParams() const { - const FunctionProtoType *FPT = getType()->getAs(); + const auto *FPT = getType()->getAs(); return FPT ? FPT->getNumParams() : 0; } @@ -2818,7 +2807,7 @@ QualType RetType = getReturnType(); if (RetType->isRecordType()) { const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl(); - const CXXMethodDecl *MD = dyn_cast(this); + const auto *MD = dyn_cast(this); if (Ret && Ret->hasAttr() && !(MD && MD->getCorrespondingMethodInClass(Ret, true))) return true; @@ -3315,7 +3304,7 @@ if (!isImplicit() || getDeclName()) return false; - if (const RecordType *Record = getType()->getAs()) + if (const auto *Record = getType()->getAs()) return Record->getDecl()->isAnonymousStructOrUnion(); return false; @@ -3323,7 +3312,7 @@ unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const { assert(isBitField() && "not a bitfield"); - Expr *BitWidth = static_cast(InitStorage.getPointer()); + auto *BitWidth = static_cast(InitStorage.getPointer()); return BitWidth->EvaluateKnownConstInt(Ctx).getZExtValue(); } @@ -3352,7 +3341,7 @@ case ISK_BitWidthOrNothing: case ISK_InClassCopyInit: case ISK_InClassListInit: - if (const Expr *E = static_cast(InitStorage.getPointer())) + if (const auto *E = static_cast(InitStorage.getPointer())) return SourceRange(getInnerLocStart(), E->getLocEnd()); // FALLTHROUGH @@ -3399,7 +3388,7 @@ void TagDecl::startDefinition() { IsBeingDefined = true; - if (CXXRecordDecl *D = dyn_cast(this)) { + if (auto *D = dyn_cast(this)) { struct CXXRecordDecl::DefinitionData *Data = new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); for (auto I : redecls()) @@ -3432,7 +3421,7 @@ } } - if (const CXXRecordDecl *CXXRD = dyn_cast(this)) + if (const auto *CXXRD = dyn_cast(this)) return CXXRD->getDefinition(); for (auto R : redecls()) @@ -3484,9 +3473,8 @@ IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed) { - EnumDecl *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl, - IsScoped, IsScopedUsingClassTag, - IsFixed); + auto *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl, + IsScoped, IsScopedUsingClassTag, IsFixed); Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules; C.getTypeDeclType(Enum, PrevDecl); return Enum; @@ -3659,7 +3647,7 @@ !Context.getLangOpts().SanitizeAddressFieldPadding) return false; const auto &Blacklist = Context.getSanitizerBlacklist(); - const CXXRecordDecl *CXXRD = dyn_cast(this); + const auto *CXXRD = dyn_cast(this); // We may be able to relax some of these requirements. int ReasonToReject = -1; if (!CXXRD || CXXRD->isExternCContext()) @@ -3700,9 +3688,9 @@ if (I->getIdentifier()) return I; - if (const RecordType *RT = I->getType()->getAs()) + if (const auto *RT = I->getType()->getAs()) if (const FieldDecl *NamedDataMember = - RT->getDecl()->findFirstNamedDataMember()) + RT->getDecl()->findFirstNamedDataMember()) return NamedDataMember; } @@ -4002,7 +3990,7 @@ NextLocalImport() { assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size()); - SourceLocation *StoredLocs = getTrailingObjects(); + auto *StoredLocs = getTrailingObjects(); std::uninitialized_copy(IdentifierLocs.begin(), IdentifierLocs.end(), StoredLocs); } @@ -4043,7 +4031,7 @@ if (!ImportedAndComplete.getInt()) return None; - const SourceLocation *StoredLocs = getTrailingObjects(); + const auto *StoredLocs = getTrailingObjects(); return llvm::makeArrayRef(StoredLocs, getNumModuleIdentifiers(getImportedModule())); }