From: Eugene Zelenko Date: Tue, 3 Apr 2018 00:11:50 +0000 (+0000) Subject: [AST] Fix some Clang-tidy modernize-use-auto warnings; other minor fixes (NFC). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd95e58bfcd1140aa4fced048ce9694e9107716c;p=clang [AST] Fix some Clang-tidy modernize-use-auto warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329036 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index a5e16771c2..7fd5729a32 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -20,6 +20,7 @@ #include "clang/AST/ASTUnresolvedSet.h" #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" @@ -1598,7 +1599,7 @@ public: /// \brief If the class is a local class [class.local], returns /// the enclosing function declaration. const FunctionDecl *isLocalClass() const { - if (const CXXRecordDecl *RD = dyn_cast(getDeclContext())) + if (const auto *RD = dyn_cast(getDeclContext())) return RD->isLocalClass(); return dyn_cast(getDeclContext()); @@ -2393,7 +2394,7 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } /// \brief Get the initializer. - Expr *getInit() const { return static_cast(Init); } + Expr *getInit() const { return static_cast(Init); } }; /// Description of a constructor that was inherited from a base class. @@ -3047,14 +3048,14 @@ public: /// \brief Retrieve the namespace declaration aliased by this directive. NamespaceDecl *getNamespace() { - if (NamespaceAliasDecl *AD = dyn_cast(Namespace)) + if (auto *AD = dyn_cast(Namespace)) return AD->getNamespace(); return cast(Namespace); } const NamespaceDecl *getNamespace() const { - return const_cast(this)->getNamespace(); + return const_cast(this)->getNamespace(); } /// Returns the location of the alias name, i.e. 'foo' in diff --git a/include/clang/AST/DeclFriend.h b/include/clang/AST/DeclFriend.h index 5d1c6b86fe..47fb68bf42 100644 --- a/include/clang/AST/DeclFriend.h +++ b/include/clang/AST/DeclFriend.h @@ -148,13 +148,13 @@ public: /// Retrieves the source range for the friend declaration. SourceRange getSourceRange() const override LLVM_READONLY { if (NamedDecl *ND = getFriendDecl()) { - if (FunctionDecl *FD = dyn_cast(ND)) + if (const auto *FD = dyn_cast(ND)) return FD->getSourceRange(); - if (FunctionTemplateDecl *FTD = dyn_cast(ND)) + if (const auto *FTD = dyn_cast(ND)) return FTD->getSourceRange(); - if (ClassTemplateDecl *CTD = dyn_cast(ND)) + if (const auto *CTD = dyn_cast(ND)) return CTD->getSourceRange(); - if (DeclaratorDecl *DD = dyn_cast(ND)) { + if (const auto *DD = dyn_cast(ND)) { if (DD->getOuterLocStart() != DD->getInnerLocStart()) return DD->getSourceRange(); } diff --git a/include/clang/AST/ExternalASTSource.h b/include/clang/AST/ExternalASTSource.h index be013c5d6b..71c75e101c 100644 --- a/include/clang/AST/ExternalASTSource.h +++ b/include/clang/AST/ExternalASTSource.h @@ -19,7 +19,6 @@ #include "clang/AST/DeclBase.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/Module.h" -#include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" @@ -447,7 +446,7 @@ public: /// Set the value of this pointer, in the current generation. void set(T NewValue) { - if (LazyData *LazyVal = Value.template dyn_cast()) { + if (auto *LazyVal = Value.template dyn_cast()) { LazyVal->LastValue = NewValue; return; } @@ -459,7 +458,7 @@ public: /// Get the value of this pointer, updating its owner if necessary. T get(Owner O) { - if (LazyData *LazyVal = Value.template dyn_cast()) { + if (auto *LazyVal = Value.template dyn_cast()) { if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); (LazyVal->ExternalSource->*Update)(O); @@ -471,7 +470,7 @@ public: /// Get the most recently computed value of this pointer without updating it. T getNotUpdated() const { - if (LazyData *LazyVal = Value.template dyn_cast()) + if (auto *LazyVal = Value.template dyn_cast()) return LazyVal->LastValue; return Value.template get(); } diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h index 86b0f356e7..e4bf43ca0a 100644 --- a/include/clang/AST/Redeclarable.h +++ b/include/clang/AST/Redeclarable.h @@ -321,7 +321,7 @@ public: /// \brief Return the first declaration of this declaration or itself if this /// is the only declaration. decl_type *getFirstDecl() { - decl_type *D = static_cast(this); + auto *D = static_cast(this); if (!D->isFromASTFile()) return D; return cast(getPrimaryMergedDecl(const_cast(D))); @@ -330,7 +330,7 @@ public: /// \brief Return the first declaration of this declaration or itself if this /// is the only declaration. const decl_type *getFirstDecl() const { - const decl_type *D = static_cast(this); + const auto *D = static_cast(this); if (!D->isFromASTFile()) return D; return cast(getPrimaryMergedDecl(const_cast(D))); diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index aa8f3d9a73..2cf85e0cb7 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -455,6 +455,7 @@ public: using const_child_range = llvm::iterator_range; child_range children(); + const_child_range children() const { auto Children = const_cast(this)->children(); return const_child_range(Children.begin(), Children.end()); @@ -543,9 +544,11 @@ public: using decl_const_range = llvm::iterator_range; decl_range decls() { return decl_range(decl_begin(), decl_end()); } + decl_const_range decls() const { return decl_const_range(decl_begin(), decl_end()); } + decl_iterator decl_begin() { return DG.begin(); } decl_iterator decl_end() { return DG.end(); } const_decl_iterator decl_begin() const { return DG.begin(); } @@ -638,6 +641,7 @@ public: body_iterator body_begin() { return getTrailingObjects(); } body_iterator body_end() { return body_begin() + size(); } Stmt *body_front() { return !body_empty() ? body_begin()[0] : nullptr; } + Stmt *body_back() { return !body_empty() ? body_begin()[size() - 1] : nullptr; } @@ -657,6 +661,7 @@ public: const_body_iterator body_begin() const { return getTrailingObjects(); } + const_body_iterator body_end() const { return body_begin() + size(); } const Stmt *body_front() const { @@ -795,7 +800,7 @@ public: SourceLocation getLocEnd() const LLVM_READONLY { // Handle deeply nested case statements with iteration instead of recursion. const CaseStmt *CS = this; - while (const CaseStmt *CS2 = dyn_cast(CS->getSubStmt())) + while (const auto *CS2 = dyn_cast(CS->getSubStmt())) CS = CS2; return CS->getSubStmt()->getLocEnd(); @@ -843,7 +848,7 @@ public: }; inline SourceLocation SwitchCase::getLocEnd() const { - if (const CaseStmt *CS = dyn_cast(this)) + if (const auto *CS = dyn_cast(this)) return CS->getLocEnd(); return cast(this)->getLocEnd(); } @@ -906,7 +911,7 @@ class AttributedStmt final } explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) - : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { + : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr); } @@ -1512,8 +1517,8 @@ public: bool isVolatile() const { return IsVolatile; } void setVolatile(bool V) { IsVolatile = V; } - SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } - SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } + SourceLocation getLocStart() const LLVM_READONLY { return {}; } + SourceLocation getLocEnd() const LLVM_READONLY { return {}; } //===--- Asm String Analysis ---===// @@ -1686,9 +1691,7 @@ public: bool isString() const { return MyKind == String; } bool isOperand() const { return MyKind == Operand; } - const std::string &getString() const { - return Str; - } + const std::string &getString() const { return Str; } unsigned getOperandNo() const { assert(isOperand()); @@ -1718,15 +1721,13 @@ public: //===--- Output operands ---===// - IdentifierInfo *getOutputIdentifier(unsigned i) const { - return Names[i]; - } + IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; } StringRef getOutputName(unsigned i) const { if (IdentifierInfo *II = getOutputIdentifier(i)) return II->getName(); - return StringRef(); + return {}; } StringRef getOutputConstraint(unsigned i) const; @@ -1754,7 +1755,7 @@ public: if (IdentifierInfo *II = getInputIdentifier(i)) return II->getName(); - return StringRef(); + return {}; } StringRef getInputConstraint(unsigned i) const; @@ -1941,7 +1942,7 @@ public: } child_range children() { - return child_range(Children,Children+2); + return child_range(Children, Children+2); } static bool classof(const Stmt *T) { @@ -2022,7 +2023,7 @@ public: SEHFinallyStmt *getFinallyHandler() const; child_range children() { - return child_range(Children,Children+2); + return child_range(Children, Children+2); } static bool classof(const Stmt *T) { diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index b805160a27..13d4a3eb6a 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -85,7 +85,7 @@ public: template T getAs() const { if (!T::isKind(*this)) - return T(); + return {}; T t; TypeLoc& tl = t; tl = *this; @@ -276,7 +276,7 @@ public: UnqualTypeLoc getUnqualifiedLoc() const { unsigned align = TypeLoc::getLocalAlignmentForType(QualType(getTypePtr(), 0)); - uintptr_t dataInt = reinterpret_cast(Data); + auto dataInt = reinterpret_cast(Data); dataInt = llvm::alignTo(dataInt, align); return UnqualTypeLoc(getTypePtr(), reinterpret_cast(dataInt)); } @@ -429,7 +429,7 @@ protected: } void *getNonLocalData() const { - uintptr_t data = reinterpret_cast(Base::Data); + auto data = reinterpret_cast(Base::Data); data += asDerived()->getLocalDataSize(); data = llvm::alignTo(data, getNextTypeAlign()); return reinterpret_cast(data); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ea96a07763..a85a22ac95 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -47,6 +47,7 @@ #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CommentOptions.h" +#include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -130,35 +131,34 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { return nullptr; // User can not attach documentation to implicit instantiations. - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (VD->isStaticDataMember() && VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const CXXRecordDecl *CRD = dyn_cast(D)) { + if (const auto *CRD = dyn_cast(D)) { if (CRD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const ClassTemplateSpecializationDecl *CTSD = - dyn_cast(D)) { + if (const auto *CTSD = dyn_cast(D)) { TemplateSpecializationKind TSK = CTSD->getSpecializationKind(); if (TSK == TSK_ImplicitInstantiation || TSK == TSK_Undeclared) return nullptr; } - if (const EnumDecl *ED = dyn_cast(D)) { + if (const auto *ED = dyn_cast(D)) { if (ED->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const TagDecl *TD = dyn_cast(D)) { + if (const auto *TD = dyn_cast(D)) { // When tag declaration (but not definition!) is part of the // decl-specifier-seq of some other declaration, it doesn't get comment if (TD->isEmbeddedInDeclarator() && !TD->isCompleteDefinition()) @@ -201,7 +201,7 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { // declared via a macro. Try using declaration's starting location as // the "declaration location". DeclLoc = D->getLocStart(); - } else if (const TagDecl *TD = dyn_cast(D)) { + } else if (const auto *TD = dyn_cast(D)) { // If location of the tag decl is inside a macro, but the spelling of // the tag name comes from a macro argument, it looks like a special // macro like NS_ENUM is being used to define the tag decl. In that @@ -312,7 +312,7 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { /// refer to the actual template. /// If we have an implicit instantiation, adjust 'D' to refer to template. static const Decl *adjustDeclToTemplate(const Decl *D) { - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // Is this function declaration part of a function template? if (const FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate()) return FTD; @@ -332,7 +332,7 @@ static const Decl *adjustDeclToTemplate(const Decl *D) { return D; } - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { // Static data member is instantiated from a member definition of a class // template? if (VD->isStaticDataMember()) @@ -341,15 +341,14 @@ static const Decl *adjustDeclToTemplate(const Decl *D) { return D; } - if (const CXXRecordDecl *CRD = dyn_cast(D)) { + if (const auto *CRD = dyn_cast(D)) { // Is this class declaration part of a class template? if (const ClassTemplateDecl *CTD = CRD->getDescribedClassTemplate()) return CTD; // Class is an implicit instantiation of a class template or partial // specialization? - if (const ClassTemplateSpecializationDecl *CTSD = - dyn_cast(CRD)) { + if (const auto *CTSD = dyn_cast(CRD)) { if (CTSD->getSpecializationKind() != TSK_ImplicitInstantiation) return D; llvm::PointerUnion(D)) { + if (const auto *ED = dyn_cast(D)) { // Enum is instantiated from a member definition of a class template? if (const EnumDecl *MemberDecl = ED->getInstantiatedFromMemberEnum()) return MemberDecl; @@ -453,7 +452,7 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl( static void addRedeclaredMethods(const ObjCMethodDecl *ObjCMethod, SmallVectorImpl &Redeclared) { const DeclContext *DC = ObjCMethod->getDeclContext(); - if (const ObjCImplDecl *IMD = dyn_cast(DC)) { + if (const auto *IMD = dyn_cast(DC)) { const ObjCInterfaceDecl *ID = IMD->getClassInterface(); if (!ID) return; @@ -469,7 +468,7 @@ static void addRedeclaredMethods(const ObjCMethodDecl *ObjCMethod, comments::FullComment *ASTContext::cloneFullComment(comments::FullComment *FC, const Decl *D) const { - comments::DeclInfo *ThisDeclInfo = new (*this) comments::DeclInfo; + auto *ThisDeclInfo = new (*this) comments::DeclInfo; ThisDeclInfo->CommentDecl = D; ThisDeclInfo->IsFilled = false; ThisDeclInfo->fill(); @@ -513,7 +512,7 @@ comments::FullComment *ASTContext::getCommentForDecl( if (!RC) { if (isa(D) || isa(D)) { SmallVector Overridden; - const ObjCMethodDecl *OMD = dyn_cast(D); + const auto *OMD = dyn_cast(D); if (OMD && OMD->isPropertyAccessor()) if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) if (comments::FullComment *FC = getCommentForDecl(PDecl, PP)) @@ -525,28 +524,28 @@ comments::FullComment *ASTContext::getCommentForDecl( if (comments::FullComment *FC = getCommentForDecl(Overridden[i], PP)) return cloneFullComment(FC, D); } - else if (const TypedefNameDecl *TD = dyn_cast(D)) { + else if (const auto *TD = dyn_cast(D)) { // Attach any tag type's documentation to its typedef if latter // does not have one of its own. QualType QT = TD->getUnderlyingType(); - if (const TagType *TT = QT->getAs()) + if (const auto *TT = QT->getAs()) if (const Decl *TD = TT->getDecl()) if (comments::FullComment *FC = getCommentForDecl(TD, PP)) return cloneFullComment(FC, D); } - else if (const ObjCInterfaceDecl *IC = dyn_cast(D)) { + else if (const auto *IC = dyn_cast(D)) { while (IC->getSuperClass()) { IC = IC->getSuperClass(); if (comments::FullComment *FC = getCommentForDecl(IC, PP)) return cloneFullComment(FC, D); } } - else if (const ObjCCategoryDecl *CD = dyn_cast(D)) { + else if (const auto *CD = dyn_cast(D)) { if (const ObjCInterfaceDecl *IC = CD->getClassInterface()) if (comments::FullComment *FC = getCommentForDecl(IC, PP)) return cloneFullComment(FC, D); } - else if (const CXXRecordDecl *RD = dyn_cast(D)) { + else if (const auto *RD = dyn_cast(D)) { if (!(RD = RD->getDefinition())) return nullptr; // Check non-virtual bases. @@ -606,13 +605,13 @@ ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID, for (TemplateParameterList::const_iterator P = Params->begin(), PEnd = Params->end(); P != PEnd; ++P) { - if (TemplateTypeParmDecl *TTP = dyn_cast(*P)) { + if (const auto *TTP = dyn_cast(*P)) { ID.AddInteger(0); ID.AddBoolean(TTP->isParameterPack()); continue; } - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(*P)) { + if (const auto *NTTP = dyn_cast(*P)) { ID.AddInteger(1); ID.AddBoolean(NTTP->isParameterPack()); ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr()); @@ -628,7 +627,7 @@ ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID, continue; } - TemplateTemplateParmDecl *TTP = cast(*P); + auto *TTP = cast(*P); ID.AddInteger(2); Profile(ID, TTP); } @@ -653,7 +652,7 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( for (TemplateParameterList::const_iterator P = Params->begin(), PEnd = Params->end(); P != PEnd; ++P) { - if (TemplateTypeParmDecl *TTP = dyn_cast(*P)) + if (const auto *TTP = dyn_cast(*P)) CanonParams.push_back( TemplateTypeParmDecl::Create(*this, getTranslationUnitDecl(), SourceLocation(), @@ -661,8 +660,7 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( TTP->getDepth(), TTP->getIndex(), nullptr, false, TTP->isParameterPack())); - else if (NonTypeTemplateParmDecl *NTTP - = dyn_cast(*P)) { + else if (const auto *NTTP = dyn_cast(*P)) { QualType T = getCanonicalType(NTTP->getType()); TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); NonTypeTemplateParmDecl *Param; @@ -814,13 +812,13 @@ ASTContext::~ASTContext() { const ASTRecordLayout*>::iterator I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) // Increment in loop to prevent using deallocated memory. - if (ASTRecordLayout *R = const_cast((I++)->second)) + if (auto *R = const_cast((I++)->second)) R->Destroy(*this); for (llvm::DenseMap::iterator I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { // Increment in loop to prevent using deallocated memory. - if (ASTRecordLayout *R = const_cast((I++)->second)) + if (auto *R = const_cast((I++)->second)) R->Destroy(*this); } @@ -968,7 +966,7 @@ void ASTContext::PerModuleInitializers::resolve(ASTContext &Ctx) { void ASTContext::addModuleInitializer(Module *M, Decl *D) { // One special case: if we add a module initializer that imports another // module, and that module's only initializer is an ImportDecl, simplify. - if (auto *ID = dyn_cast(D)) { + if (const auto *ID = dyn_cast(D)) { auto It = ModuleInitializers.find(ID->getImportedModule()); // Maybe the ImportDecl does nothing at all. (Common case.) @@ -999,7 +997,7 @@ void ASTContext::addLazyModuleInitializers(Module *M, ArrayRef IDs) { IDs.begin(), IDs.end()); } -ArrayRef ASTContext::getModuleInitializers(Module *M) { +ArrayRef ASTContext::getModuleInitializers(Module *M) { auto It = ModuleInitializers.find(M); if (It == ModuleInitializers.end()) return None; @@ -1081,7 +1079,7 @@ TypedefDecl *ASTContext::getUInt128Decl() const { } void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { - BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); + auto *Ty = new (*this, TypeAlignment) BuiltinType(K); R = CanQualType::CreateUnsafe(QualType(Ty, 0)); Types.push_back(Ty); } @@ -1278,7 +1276,7 @@ ASTContext::getTemplateOrSpecializationInfo(const VarDecl *Var) { llvm::DenseMap::iterator Pos = TemplateOrInstantiation.find(Var); if (Pos == TemplateOrInstantiation.end()) - return TemplateOrSpecializationInfo(); + return {}; return Pos->second; } @@ -1414,13 +1412,13 @@ void ASTContext::getOverriddenMethods( SmallVectorImpl &Overridden) const { assert(D); - if (const CXXMethodDecl *CXXMethod = dyn_cast(D)) { + if (const auto *CXXMethod = dyn_cast(D)) { Overridden.append(overridden_methods_begin(CXXMethod), overridden_methods_end(CXXMethod)); return; } - const ObjCMethodDecl *Method = dyn_cast(D); + const auto *Method = dyn_cast(D); if (!Method) return; @@ -1449,7 +1447,7 @@ void ASTContext::addedLocalImportDecl(ImportDecl *Import) { /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified /// scalar floating point type. const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { - const BuiltinType *BT = T->getAs(); + const auto *BT = T->getAs(); assert(BT && "Not a floating point type!"); switch (BT->getKind()) { default: llvm_unreachable("Not a floating point type!"); @@ -1492,9 +1490,9 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { // else about the declaration and its type. if (UseAlignAttrOnly) { // do nothing - } else if (const ValueDecl *VD = dyn_cast(D)) { + } else if (const auto *VD = dyn_cast(D)) { QualType T = VD->getType(); - if (const ReferenceType *RT = T->getAs()) { + if (const auto *RT = T->getAs()) { if (ForAlignof) T = RT->getPointeeType(); else @@ -1519,7 +1517,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); if (BaseT.getQualifiers().hasUnaligned()) Align = Target->getCharWidth(); - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (VD->hasGlobalStorage() && !ForAlignof) Align = std::max(Align, getTargetInfo().getMinGlobalAlign()); } @@ -1530,7 +1528,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { // a max-field-alignment constraint (#pragma pack). So calculate // the actual alignment of the field within the struct, and then // (as we're expected to) constrain that by the alignment of the type. - if (const FieldDecl *Field = dyn_cast(VD)) { + if (const auto *Field = dyn_cast(VD)) { const RecordDecl *Parent = Field->getParent(); // We can only produce a sensible answer if the record is valid. if (!Parent->isInvalidDecl()) { @@ -1569,7 +1567,7 @@ ASTContext::getTypeInfoDataSizeInChars(QualType T) const { // of a base-class subobject. We decide whether that's possible // during class layout, so here we can just trust the layout results. if (getLangOpts().CPlusPlus) { - if (const RecordType *RT = T->getAs()) { + if (const auto *RT = T->getAs()) { const ASTRecordLayout &layout = getASTRecordLayout(RT->getDecl()); sizeAndAlign.first = layout.getDataSize(); } @@ -1600,7 +1598,7 @@ static getConstantArrayInfoInChars(const ASTContext &Context, std::pair ASTContext::getTypeInfoInChars(const Type *T) const { - if (const ConstantArrayType *CAT = dyn_cast(T)) + if (const auto *CAT = dyn_cast(T)) return getConstantArrayInfoInChars(*this, CAT); TypeInfo Info = getTypeInfo(T); return std::make_pair(toCharUnitsFromBits(Info.Width), @@ -1622,7 +1620,7 @@ bool ASTContext::isAlignmentRequired(QualType T) const { unsigned ASTContext::getTypeAlignIfKnown(QualType T) const { // An alignment on a typedef overrides anything else. - if (auto *TT = T->getAs()) + if (const auto *TT = T->getAs()) if (unsigned Align = TT->getDecl()->getMaxAlignment()) return Align; @@ -1633,12 +1631,12 @@ unsigned ASTContext::getTypeAlignIfKnown(QualType T) const { // If we had an array type, its element type might be a typedef // type with an alignment attribute. - if (auto *TT = T->getAs()) + if (const auto *TT = T->getAs()) if (unsigned Align = TT->getDecl()->getMaxAlignment()) return Align; // Otherwise, see if the declaration of the type had an attribute. - if (auto *TT = T->getAs()) + if (const auto *TT = T->getAs()) return TT->getDecl()->getMaxAlignment(); return 0; @@ -1692,7 +1690,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { break; case Type::ConstantArray: { - const ConstantArrayType *CAT = cast(T); + const auto *CAT = cast(T); TypeInfo EltInfo = getTypeInfo(CAT->getElementType()); uint64_t Size = CAT->getSize().getZExtValue(); @@ -1707,7 +1705,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { } case Type::ExtVector: case Type::Vector: { - const VectorType *VT = cast(T); + const auto *VT = cast(T); TypeInfo EltInfo = getTypeInfo(VT->getElementType()); Width = EltInfo.Width * VT->getNumElements(); Align = Width; @@ -1850,7 +1848,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Align = Target->getPointerAlign(AS); break; case Type::MemberPointer: { - const MemberPointerType *MPT = cast(T); + const auto *MPT = cast(T); CXXABI::MemberPointerInfo MPI = ABI->getMemberPointerInfo(MPT); Width = MPI.Width; Align = MPI.Align; @@ -1870,7 +1868,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case Type::Decayed: return getTypeInfo(cast(T)->getAdjustedType().getTypePtr()); case Type::ObjCInterface: { - const ObjCInterfaceType *ObjCI = cast(T); + const auto *ObjCI = cast(T); const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); Width = toBits(Layout.getSize()); Align = toBits(Layout.getAlignment()); @@ -1878,7 +1876,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { } case Type::Record: case Type::Enum: { - const TagType *TT = cast(T); + const auto *TT = cast(T); if (TT->getDecl()->isInvalidDecl()) { Width = 8; @@ -1886,7 +1884,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { break; } - if (const EnumType *ET = dyn_cast(TT)) { + if (const auto *ET = dyn_cast(TT)) { const EnumDecl *ED = ET->getDecl(); TypeInfo Info = getTypeInfo(ED->getIntegerType()->getUnqualifiedDesugaredType()); @@ -1897,7 +1895,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { return Info; } - const RecordType *RT = cast(TT); + const auto *RT = cast(TT); const RecordDecl *RD = RT->getDecl(); const ASTRecordLayout &Layout = getASTRecordLayout(RD); Width = toBits(Layout.getSize()); @@ -1912,7 +1910,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case Type::Auto: case Type::DeducedTemplateSpecialization: { - const DeducedType *A = cast(T); + const auto *A = cast(T); assert(!A->getDeducedType().isNull() && "cannot request the size of an undeduced or dependent auto type"); return getTypeInfo(A->getDeducedType().getTypePtr()); @@ -2035,9 +2033,9 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const { return ABIAlign; // Double and long long should be naturally aligned if possible. - if (const ComplexType *CT = T->getAs()) + if (const auto *CT = T->getAs()) T = CT->getElementType().getTypePtr(); - if (const EnumType *ET = T->getAs()) + if (const auto *ET = T->getAs()) T = ET->getDecl()->getIntegerType().getTypePtr(); if (T->isSpecificBuiltinType(BuiltinType::Double) || T->isSpecificBuiltinType(BuiltinType::LongLong) || @@ -2093,7 +2091,7 @@ void ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, for (const auto *I : OI->ivars()) Ivars.push_back(I); } else { - ObjCInterfaceDecl *IDecl = const_cast(OI); + auto *IDecl = const_cast(OI); for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; Iv= Iv->getNextIvar()) Ivars.push_back(Iv); @@ -2104,7 +2102,7 @@ void ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, /// those inherited by it. void ASTContext::CollectInheritedProtocols(const Decl *CDecl, llvm::SmallPtrSet &Protocols) { - if (const ObjCInterfaceDecl *OI = dyn_cast(CDecl)) { + if (const auto *OI = dyn_cast(CDecl)) { // We can use protocol_iterator here instead of // all_referenced_protocol_iterator since we are walking all categories. for (auto *Proto : OI->all_referenced_protocols()) { @@ -2120,11 +2118,11 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl, CollectInheritedProtocols(SD, Protocols); SD = SD->getSuperClass(); } - } else if (const ObjCCategoryDecl *OC = dyn_cast(CDecl)) { + } else if (const auto *OC = dyn_cast(CDecl)) { for (auto *Proto : OC->protocols()) { CollectInheritedProtocols(Proto, Protocols); } - } else if (const ObjCProtocolDecl *OP = dyn_cast(CDecl)) { + } else if (const auto *OP = dyn_cast(CDecl)) { // Insert the protocol. if (!Protocols.insert( const_cast(OP->getCanonicalDecl())).second) @@ -2266,7 +2264,7 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const { return true; if (Ty->isMemberPointerType()) { - const MemberPointerType *MPT = Ty->getAs(); + const auto *MPT = Ty->getAs(); return !ABI->getMemberPointerInfo(MPT).HasPadding; } @@ -2379,14 +2377,11 @@ void ASTContext::setObjCMethodRedeclaration(const ObjCMethodDecl *MD, const ObjCInterfaceDecl *ASTContext::getObjContainingInterface( const NamedDecl *ND) const { - if (const ObjCInterfaceDecl *ID = - dyn_cast(ND->getDeclContext())) + if (const auto *ID = dyn_cast(ND->getDeclContext())) return ID; - if (const ObjCCategoryDecl *CD = - dyn_cast(ND->getDeclContext())) + if (const auto *CD = dyn_cast(ND->getDeclContext())) return CD->getClassInterface(); - if (const ObjCImplDecl *IMD = - dyn_cast(ND->getDeclContext())) + if (const auto *IMD = dyn_cast(ND->getDeclContext())) return IMD->getClassInterface(); return nullptr; @@ -2419,7 +2414,7 @@ TypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T, assert(DataSize == TypeLoc::getFullDataSizeForType(T) && "incorrect data size provided to CreateTypeSourceInfo!"); - TypeSourceInfo *TInfo = + auto *TInfo = (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); new (TInfo) TypeSourceInfo(T); return TInfo; @@ -2472,7 +2467,7 @@ ASTContext::getExtQualType(const Type *baseType, Qualifiers quals) const { (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos); } - ExtQuals *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); + auto *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); ExtQualNodes.InsertNode(eq, insertPos); return QualType(eq, fastQuals); } @@ -2524,7 +2519,7 @@ QualType ASTContext::getObjCGCQualType(QualType T, if (CanT.getObjCGCAttr() == GCAttr) return T; - if (const PointerType *ptr = T->getAs()) { + if (const auto *ptr = T->getAs()) { QualType Pointee = ptr->getPointeeType(); if (Pointee->isAnyPointerType()) { QualType ResultType = getObjCGCQualType(Pointee, GCAttr); @@ -2552,10 +2547,10 @@ const FunctionType *ASTContext::adjustFunctionType(const FunctionType *T, return T; QualType Result; - if (const FunctionNoProtoType *FNPT = dyn_cast(T)) { + if (const auto *FNPT = dyn_cast(T)) { Result = getFunctionNoProtoType(FNPT->getReturnType(), Info); } else { - const FunctionProtoType *FPT = cast(T); + const auto *FPT = cast(T); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); EPI.ExtInfo = Info; Result = getFunctionType(FPT->getReturnType(), FPT->getParamTypes(), EPI); @@ -2568,7 +2563,7 @@ void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType) { FD = FD->getMostRecentDecl(); while (true) { - const FunctionProtoType *FPT = FD->getType()->castAs(); + const auto *FPT = FD->getType()->castAs(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FD->setType(getFunctionType(ResultType, FPT->getParamTypes(), EPI)); if (FunctionDecl *Next = FD->getPreviousDecl()) @@ -2587,12 +2582,12 @@ void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ASTContext::getFunctionTypeWithExceptionSpec( QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) { // Might have some parens. - if (auto *PT = dyn_cast(Orig)) + if (const auto *PT = dyn_cast(Orig)) return getParenType( getFunctionTypeWithExceptionSpec(PT->getInnerType(), ESI)); // Might have a calling-convention attribute. - if (auto *AT = dyn_cast(Orig)) + if (const auto *AT = dyn_cast(Orig)) return getAttributedType( AT->getAttrKind(), getFunctionTypeWithExceptionSpec(AT->getModifiedType(), ESI), @@ -2600,7 +2595,7 @@ QualType ASTContext::getFunctionTypeWithExceptionSpec( // Anything else must be a function type. Rebuild it with the new exception // specification. - const FunctionProtoType *Proto = cast(Orig); + const auto *Proto = cast(Orig); return getFunctionType( Proto->getReturnType(), Proto->getParamTypes(), Proto->getExtProtoInfo().withExceptionSpec(ESI)); @@ -2672,7 +2667,7 @@ QualType ASTContext::getComplexType(QualType T) const { ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - ComplexType *New = new (*this, TypeAlignment) ComplexType(T, Canonical); + auto *New = new (*this, TypeAlignment) ComplexType(T, Canonical); Types.push_back(New); ComplexTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2700,7 +2695,7 @@ QualType ASTContext::getPointerType(QualType T) const { PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - PointerType *New = new (*this, TypeAlignment) PointerType(T, Canonical); + auto *New = new (*this, TypeAlignment) PointerType(T, Canonical); Types.push_back(New); PointerTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2791,8 +2786,7 @@ QualType ASTContext::getBlockPointerType(QualType T) const { BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - BlockPointerType *New - = new (*this, TypeAlignment) BlockPointerType(T, Canonical); + auto *New = new (*this, TypeAlignment) BlockPointerType(T, Canonical); Types.push_back(New); BlockPointerTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2815,7 +2809,7 @@ ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(RT, 0); - const ReferenceType *InnerRef = T->getAs(); + const auto *InnerRef = T->getAs(); // If the referencee type isn't canonical, this won't be a canonical type // either, so fill in the canonical type field. @@ -2830,9 +2824,8 @@ ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - LValueReferenceType *New - = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, - SpelledAsLValue); + auto *New = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, + SpelledAsLValue); Types.push_back(New); LValueReferenceTypes.InsertNode(New, InsertPos); @@ -2852,7 +2845,7 @@ QualType ASTContext::getRValueReferenceType(QualType T) const { RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(RT, 0); - const ReferenceType *InnerRef = T->getAs(); + const auto *InnerRef = T->getAs(); // If the referencee type isn't canonical, this won't be a canonical type // either, so fill in the canonical type field. @@ -2867,8 +2860,7 @@ QualType ASTContext::getRValueReferenceType(QualType T) const { assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - RValueReferenceType *New - = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); + auto *New = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); Types.push_back(New); RValueReferenceTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2898,8 +2890,7 @@ QualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const { MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - MemberPointerType *New - = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); + auto *New = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); Types.push_back(New); MemberPointerTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2943,7 +2934,7 @@ QualType ASTContext::getConstantArrayType(QualType EltTy, assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - ConstantArrayType *New = new(*this,TypeAlignment) + auto *New = new (*this,TypeAlignment) ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); ConstantArrayTypes.InsertNode(New, InsertPos); Types.push_back(New); @@ -3015,7 +3006,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const { break; case Type::LValueReference: { - const LValueReferenceType *lv = cast(ty); + const auto *lv = cast(ty); result = getLValueReferenceType( getVariableArrayDecayedType(lv->getPointeeType()), lv->isSpelledAsLValue()); @@ -3023,20 +3014,20 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const { } case Type::RValueReference: { - const RValueReferenceType *lv = cast(ty); + const auto *lv = cast(ty); result = getRValueReferenceType( getVariableArrayDecayedType(lv->getPointeeType())); break; } case Type::Atomic: { - const AtomicType *at = cast(ty); + const auto *at = cast(ty); result = getAtomicType(getVariableArrayDecayedType(at->getValueType())); break; } case Type::ConstantArray: { - const ConstantArrayType *cat = cast(ty); + const auto *cat = cast(ty); result = getConstantArrayType( getVariableArrayDecayedType(cat->getElementType()), cat->getSize(), @@ -3046,7 +3037,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const { } case Type::DependentSizedArray: { - const DependentSizedArrayType *dat = cast(ty); + const auto *dat = cast(ty); result = getDependentSizedArrayType( getVariableArrayDecayedType(dat->getElementType()), dat->getSizeExpr(), @@ -3058,7 +3049,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const { // Turn incomplete types into [*] types. case Type::IncompleteArray: { - const IncompleteArrayType *iat = cast(ty); + const auto *iat = cast(ty); result = getVariableArrayType( getVariableArrayDecayedType(iat->getElementType()), /*size*/ nullptr, @@ -3070,7 +3061,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const { // Turn VLA types into [*] types. case Type::VariableArray: { - const VariableArrayType *vat = cast(ty); + const auto *vat = cast(ty); result = getVariableArrayType( getVariableArrayDecayedType(vat->getElementType()), /*size*/ nullptr, @@ -3104,7 +3095,7 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Canon = getQualifiedType(Canon, canonSplit.Quals); } - VariableArrayType *New = new(*this, TypeAlignment) + auto *New = new (*this, TypeAlignment) VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); VariableArrayTypes.push_back(New); @@ -3129,7 +3120,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType, // initializer. We do no canonicalization here at all, which is okay // because they can't be used in most locations. if (!numElements) { - DependentSizedArrayType *newType + auto *newType = new (*this, TypeAlignment) DependentSizedArrayType(*this, elementType, QualType(), numElements, ASM, elementTypeQuals, @@ -3175,7 +3166,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType, // Otherwise, we need to build a type which follows the spelling // of the element type. - DependentSizedArrayType *sugaredType + auto *sugaredType = new (*this, TypeAlignment) DependentSizedArrayType(*this, elementType, canon, numElements, ASM, elementTypeQuals, brackets); @@ -3211,7 +3202,7 @@ QualType ASTContext::getIncompleteArrayType(QualType elementType, assert(!existing && "Shouldn't be in the map!"); (void) existing; } - IncompleteArrayType *newType = new (*this, TypeAlignment) + auto *newType = new (*this, TypeAlignment) IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); IncompleteArrayTypes.InsertNode(newType, insertPos); @@ -3243,7 +3234,7 @@ QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts, VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - VectorType *New = new (*this, TypeAlignment) + auto *New = new (*this, TypeAlignment) VectorType(vecType, NumElts, Canonical, VecKind); VectorTypes.InsertNode(New, InsertPos); Types.push_back(New); @@ -3274,7 +3265,7 @@ ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) const { VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - ExtVectorType *New = new (*this, TypeAlignment) + auto *New = new (*this, TypeAlignment) ExtVectorType(vecType, NumElts, Canonical); VectorTypes.InsertNode(New, InsertPos); Types.push_back(New); @@ -3350,7 +3341,7 @@ QualType ASTContext::getDependentAddressSpaceType(QualType PointeeType, canonTy->getAddrSpaceExpr() == AddrSpaceExpr) return QualType(canonTy, 0); - DependentAddressSpaceType *sugaredType + auto *sugaredType = new (*this, TypeAlignment) DependentAddressSpaceType(*this, PointeeType, QualType(canonTy, 0), AddrSpaceExpr, AttrLoc); @@ -3390,7 +3381,7 @@ ASTContext::getFunctionNoProtoType(QualType ResultTy, assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - FunctionNoProtoType *New = new (*this, TypeAlignment) + auto *New = new (*this, TypeAlignment) FunctionNoProtoType(ResultTy, Canonical, Info); Types.push_back(New); FunctionNoProtoTypes.InsertNode(New, InsertPos); @@ -3604,7 +3595,7 @@ QualType ASTContext::getFunctionTypeInternal( Size += NumArgs * sizeof(FunctionProtoType::ExtParameterInfo); } - FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); + auto *FTP = (FunctionProtoType *) Allocate(Size, TypeAlignment); FunctionProtoType::ExtProtoInfo newEPI = EPI; new (FTP) FunctionProtoType(ResultTy, ArgArray, Canonical, newEPI); Types.push_back(FTP); @@ -3632,7 +3623,7 @@ QualType ASTContext::getPipeType(QualType T, bool ReadOnly) const { assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - PipeType *New = new (*this, TypeAlignment) PipeType(T, Canonical, ReadOnly); + auto *New = new (*this, TypeAlignment) PipeType(T, Canonical, ReadOnly); Types.push_back(New); PipeTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -3649,7 +3640,7 @@ QualType ASTContext::getWritePipeType(QualType T) const { #ifndef NDEBUG static bool NeedsInjectedClassNameType(const RecordDecl *D) { if (!isa(D)) return false; - const CXXRecordDecl *RD = cast(D); + const auto *RD = cast(D); if (isa(RD)) return true; if (RD->getDescribedClassTemplate() && @@ -3685,21 +3676,20 @@ QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { assert(Decl && "Passed null for Decl param"); assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); - if (const TypedefNameDecl *Typedef = dyn_cast(Decl)) + if (const auto *Typedef = dyn_cast(Decl)) return getTypedefType(Typedef); assert(!isa(Decl) && "Template type parameter types are always available."); - if (const RecordDecl *Record = dyn_cast(Decl)) { + if (const auto *Record = dyn_cast(Decl)) { assert(Record->isFirstDecl() && "struct/union has previous declaration"); assert(!NeedsInjectedClassNameType(Record)); return getRecordType(Record); - } else if (const EnumDecl *Enum = dyn_cast(Decl)) { + } else if (const auto *Enum = dyn_cast(Decl)) { assert(Enum->isFirstDecl() && "enum has previous declaration"); return getEnumType(Enum); - } else if (const UnresolvedUsingTypenameDecl *Using = - dyn_cast(Decl)) { + } else if (const auto *Using = dyn_cast(Decl)) { Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); Decl->TypeForDecl = newType; Types.push_back(newType); @@ -3718,7 +3708,7 @@ ASTContext::getTypedefType(const TypedefNameDecl *Decl, if (Canonical.isNull()) Canonical = getCanonicalType(Decl->getUnderlyingType()); - TypedefType *newType = new(*this, TypeAlignment) + auto *newType = new (*this, TypeAlignment) TypedefType(Type::Typedef, Decl, Canonical); Decl->TypeForDecl = newType; Types.push_back(newType); @@ -3732,7 +3722,7 @@ QualType ASTContext::getRecordType(const RecordDecl *Decl) const { if (PrevDecl->TypeForDecl) return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); - RecordType *newType = new (*this, TypeAlignment) RecordType(Decl); + auto *newType = new (*this, TypeAlignment) RecordType(Decl); Decl->TypeForDecl = newType; Types.push_back(newType); return QualType(newType, 0); @@ -3745,7 +3735,7 @@ QualType ASTContext::getEnumType(const EnumDecl *Decl) const { if (PrevDecl->TypeForDecl) return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); - EnumType *newType = new (*this, TypeAlignment) EnumType(Decl); + auto *newType = new (*this, TypeAlignment) EnumType(Decl); Decl->TypeForDecl = newType; Types.push_back(newType); return QualType(newType, 0); @@ -3820,7 +3810,7 @@ QualType ASTContext::getSubstTemplateTypeParmPackType( SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos); } - SubstTemplateTypeParmPackType *SubstParm + auto *SubstParm = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon, ArgPack); Types.push_back(SubstParm); @@ -3939,7 +3929,7 @@ ASTContext::getTemplateSpecializationType(TemplateName Template, sizeof(TemplateArgument) * Args.size() + (IsTypeAlias? sizeof(QualType) : 0), TypeAlignment); - TemplateSpecializationType *Spec + auto *Spec = new (Mem) TemplateSpecializationType(Template, Args, CanonType, IsTypeAlias ? Underlying : QualType()); @@ -4134,7 +4124,7 @@ ASTContext::getDependentTemplateSpecializationType( TemplateArgument ASTContext::getInjectedTemplateArg(NamedDecl *Param) { TemplateArgument Arg; - if (auto *TTP = dyn_cast(Param)) { + if (const auto *TTP = dyn_cast(Param)) { QualType ArgType = getTypeDeclType(TTP); if (TTP->isParameterPack()) ArgType = getPackExpansionType(ArgType, None); @@ -4273,7 +4263,7 @@ QualType ASTContext::getObjCObjectType( // type. ArrayRef effectiveTypeArgs = typeArgs; if (effectiveTypeArgs.empty()) { - if (auto baseObject = baseType->getAs()) + if (const auto *baseObject = baseType->getAs()) effectiveTypeArgs = baseObject->getTypeArgs(); } @@ -4321,7 +4311,7 @@ QualType ASTContext::getObjCObjectType( size += typeArgs.size() * sizeof(QualType); size += protocols.size() * sizeof(ObjCProtocolDecl *); void *mem = Allocate(size, TypeAlignment); - ObjCObjectTypeImpl *T = + auto *T = new (mem) ObjCObjectTypeImpl(canonical, baseType, typeArgs, protocols, isKindOf); @@ -4339,15 +4329,14 @@ ASTContext::applyObjCProtocolQualifiers(QualType type, bool allowOnPointerType) const { hasError = false; - if (const ObjCTypeParamType *objT = - dyn_cast(type.getTypePtr())) { + if (const auto *objT = dyn_cast(type.getTypePtr())) { return getObjCTypeParamType(objT->getDecl(), protocols); } // Apply protocol qualifiers to ObjCObjectPointerType. if (allowOnPointerType) { - if (const ObjCObjectPointerType *objPtr = - dyn_cast(type.getTypePtr())) { + if (const auto *objPtr = + dyn_cast(type.getTypePtr())) { const ObjCObjectType *objT = objPtr->getObjectType(); // Merge protocol lists and construct ObjCObjectType. SmallVector protocolsVec; @@ -4365,7 +4354,7 @@ ASTContext::applyObjCProtocolQualifiers(QualType type, } // Apply protocol qualifiers to ObjCObjectType. - if (const ObjCObjectType *objT = dyn_cast(type.getTypePtr())){ + if (const auto *objT = dyn_cast(type.getTypePtr())){ // FIXME: Check for protocols to which the class type is already // known to conform. @@ -4387,7 +4376,7 @@ ASTContext::applyObjCProtocolQualifiers(QualType type, // id if (type->isObjCIdType()) { - const ObjCObjectPointerType *objPtr = type->castAs(); + const auto *objPtr = type->castAs(); type = getObjCObjectType(ObjCBuiltinIdTy, {}, protocols, objPtr->isKindOfType()); return getObjCObjectPointerType(type); @@ -4395,7 +4384,7 @@ ASTContext::applyObjCProtocolQualifiers(QualType type, // Class if (type->isObjCClassType()) { - const ObjCObjectPointerType *objPtr = type->castAs(); + const auto *objPtr = type->castAs(); type = getObjCObjectType(ObjCBuiltinClassTy, {}, protocols, objPtr->isKindOfType()); return getObjCObjectPointerType(type); @@ -4432,8 +4421,7 @@ ASTContext::getObjCTypeParamType(const ObjCTypeParamDecl *Decl, unsigned size = sizeof(ObjCTypeParamType); size += protocols.size() * sizeof(ObjCProtocolDecl *); void *mem = Allocate(size, TypeAlignment); - ObjCTypeParamType *newType = new (mem) - ObjCTypeParamType(Decl, Canonical, protocols); + auto *newType = new (mem) ObjCTypeParamType(Decl, Canonical, protocols); Types.push_back(newType); ObjCTypeParamTypes.InsertNode(newType, InsertPos); @@ -4448,7 +4436,7 @@ bool ASTContext::ObjCObjectAdoptsQTypeProtocols(QualType QT, if (!QT->isObjCQualifiedIdType()) return false; - if (const ObjCObjectPointerType *OPT = QT->getAs()) { + if (const auto *OPT = QT->getAs()) { // If both the right and left sides have qualifiers. for (auto *Proto : OPT->quals()) { if (!IC->ClassImplementsProtocol(Proto, false)) @@ -4466,7 +4454,7 @@ bool ASTContext::QIdProtocolsAdoptObjCObjectProtocols(QualType QT, ObjCInterfaceDecl *IDecl) { if (!QT->isObjCQualifiedIdType()) return false; - const ObjCObjectPointerType *OPT = QT->getAs(); + const auto *OPT = QT->getAs(); if (!OPT) return false; if (!IDecl->hasDefinition()) @@ -4528,7 +4516,7 @@ QualType ASTContext::getObjCObjectPointerType(QualType ObjectT) const { // No match. void *Mem = Allocate(sizeof(ObjCObjectPointerType), TypeAlignment); - ObjCObjectPointerType *QType = + auto *QType = new (Mem) ObjCObjectPointerType(Canonical, ObjectT); Types.push_back(QType); @@ -4554,7 +4542,7 @@ QualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, Decl = Def; void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); - ObjCInterfaceType *T = new (Mem) ObjCInterfaceType(Decl); + auto *T = new (Mem) ObjCInterfaceType(Decl); Decl->TypeForDecl = T; Types.push_back(T); return QualType(T, 0); @@ -4601,7 +4589,7 @@ QualType ASTContext::getTypeOfExprType(Expr *tofExpr) const { /// on canonical types (which are always unique). QualType ASTContext::getTypeOfType(QualType tofType) const { QualType Canonical = getCanonicalType(tofType); - TypeOfType *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); + auto *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); Types.push_back(tot); return QualType(tot, 0); } @@ -4691,9 +4679,8 @@ QualType ASTContext::getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(AT, 0); - AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType, - Keyword, - IsDependent); + auto *AT = new (*this, TypeAlignment) + AutoType(DeducedType, Keyword, IsDependent); Types.push_back(AT); if (InsertPos) AutoTypes.InsertNode(AT, InsertPos); @@ -4714,7 +4701,7 @@ QualType ASTContext::getDeducedTemplateSpecializationType( DeducedTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(DTST, 0); - DeducedTemplateSpecializationType *DTST = new (*this, TypeAlignment) + auto *DTST = new (*this, TypeAlignment) DeducedTemplateSpecializationType(Template, DeducedType, IsDependent); Types.push_back(DTST); if (InsertPos) @@ -4744,7 +4731,7 @@ QualType ASTContext::getAtomicType(QualType T) const { AtomicType *NewIP = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - AtomicType *New = new (*this, TypeAlignment) AtomicType(T, Canonical); + auto *New = new (*this, TypeAlignment) AtomicType(T, Canonical); Types.push_back(New); AtomicTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -4871,8 +4858,8 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type, // the unqualified desugared type and then drops it on the floor. // We then have to strip that sugar back off with // getUnqualifiedDesugaredType(), which is silly. - const ArrayType *AT = - dyn_cast(splitType.Ty->getUnqualifiedDesugaredType()); + const auto *AT = + dyn_cast(splitType.Ty->getUnqualifiedDesugaredType()); // If we don't have an array, just use the results in splitType. if (!AT) { @@ -4896,16 +4883,16 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type, // build the type back up. quals.addConsistentQualifiers(splitType.Quals); - if (const ConstantArrayType *CAT = dyn_cast(AT)) { + if (const auto *CAT = dyn_cast(AT)) { return getConstantArrayType(unqualElementType, CAT->getSize(), CAT->getSizeModifier(), 0); } - if (const IncompleteArrayType *IAT = dyn_cast(AT)) { + if (const auto *IAT = dyn_cast(AT)) { return getIncompleteArrayType(unqualElementType, IAT->getSizeModifier(), 0); } - if (const VariableArrayType *VAT = dyn_cast(AT)) { + if (const auto *VAT = dyn_cast(AT)) { return getVariableArrayType(unqualElementType, VAT->getSizeExpr(), VAT->getSizeModifier(), @@ -4913,7 +4900,7 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type, VAT->getBracketsRange()); } - const DependentSizedArrayType *DSAT = cast(AT); + const auto *DSAT = cast(AT); return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(), DSAT->getSizeModifier(), 0, SourceRange()); @@ -4928,16 +4915,16 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type, /// be called in a loop that successively "unwraps" pointer and /// pointer-to-member types to compare them at each level. bool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) { - const PointerType *T1PtrType = T1->getAs(), - *T2PtrType = T2->getAs(); + const auto *T1PtrType = T1->getAs(); + const auto *T2PtrType = T2->getAs(); if (T1PtrType && T2PtrType) { T1 = T1PtrType->getPointeeType(); T2 = T2PtrType->getPointeeType(); return true; } - const MemberPointerType *T1MPType = T1->getAs(), - *T2MPType = T2->getAs(); + const auto *T1MPType = T1->getAs(); + const auto *T2MPType = T2->getAs(); if (T1MPType && T2MPType && hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0), QualType(T2MPType->getClass(), 0))) { @@ -4947,8 +4934,8 @@ bool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) { } if (getLangOpts().ObjC1) { - const ObjCObjectPointerType *T1OPType = T1->getAs(), - *T2OPType = T2->getAs(); + const auto *T1OPType = T1->getAs(); + const auto *T2OPType = T2->getAs(); if (T1OPType && T2OPType) { T1 = T1OPType->getPointeeType(); T2 = T2OPType->getPointeeType(); @@ -5016,8 +5003,7 @@ TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) const { case TemplateName::QualifiedTemplate: case TemplateName::Template: { TemplateDecl *Template = Name.getAsTemplateDecl(); - if (TemplateTemplateParmDecl *TTP - = dyn_cast(Template)) + if (auto *TTP = dyn_cast(Template)) Template = getCanonicalTemplateTemplateParmDecl(TTP); // The canonical template name is the canonical template declaration. @@ -5069,7 +5055,7 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const { return Arg; case TemplateArgument::Declaration: { - ValueDecl *D = cast(Arg.getAsDecl()->getCanonicalDecl()); + auto *D = cast(Arg.getAsDecl()->getCanonicalDecl()); return TemplateArgument(D, Arg.getParamTypeForDecl()); } @@ -5095,8 +5081,7 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const { if (Arg.pack_size() == 0) return Arg; - TemplateArgument *CanonArgs - = new (*this) TemplateArgument[Arg.pack_size()]; + auto *CanonArgs = new (*this) TemplateArgument[Arg.pack_size()]; unsigned Idx = 0; for (TemplateArgument::pack_iterator A = Arg.pack_begin(), AEnd = Arg.pack_end(); @@ -5147,7 +5132,7 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const { // types, e.g., // typedef typename T::type T1; // typedef typename T1::type T2; - if (const DependentNameType *DNT = T->getAs()) + if (const auto *DNT = T->getAs()) return NestedNameSpecifier::Create(*this, DNT->getQualifier(), const_cast(DNT->getIdentifier())); @@ -5171,7 +5156,7 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const { // Handle the non-qualified case efficiently. if (!T.hasLocalQualifiers()) { // Handle the common positive case fast. - if (const ArrayType *AT = dyn_cast(T)) + if (const auto *AT = dyn_cast(T)) return AT; } @@ -5191,7 +5176,7 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const { Qualifiers qs = split.Quals; // If we have a simple case, just return now. - const ArrayType *ATy = dyn_cast(split.Ty); + const auto *ATy = dyn_cast(split.Ty); if (!ATy || qs.empty()) return ATy; @@ -5199,17 +5184,16 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const { // qualifiers into the array element type and return a new array type. QualType NewEltTy = getQualifiedType(ATy->getElementType(), qs); - if (const ConstantArrayType *CAT = dyn_cast(ATy)) + if (const auto *CAT = dyn_cast(ATy)) return cast(getConstantArrayType(NewEltTy, CAT->getSize(), CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers())); - if (const IncompleteArrayType *IAT = dyn_cast(ATy)) + if (const auto *IAT = dyn_cast(ATy)) return cast(getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(), IAT->getIndexTypeCVRQualifiers())); - if (const DependentSizedArrayType *DSAT - = dyn_cast(ATy)) + if (const auto *DSAT = dyn_cast(ATy)) return cast( getDependentSizedArrayType(NewEltTy, DSAT->getSizeExpr(), @@ -5217,7 +5201,7 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const { DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange())); - const VariableArrayType *VAT = cast(ATy); + const auto *VAT = cast(ATy); return cast(getVariableArrayType(NewEltTy, VAT->getSizeExpr(), VAT->getSizeModifier(), @@ -5311,7 +5295,7 @@ ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { /// getFloatingRank - Return a relative rank for floating point types. /// This routine will assert if passed a built-in type that isn't a float. static FloatingRank getFloatingRank(QualType T) { - if (const ComplexType *CT = T->getAs()) + if (const auto *CT = T->getAs()) return getFloatingRank(CT->getElementType()); assert(T->getAs() && "getFloatingRank(): not a floating type"); @@ -5411,7 +5395,7 @@ unsigned ASTContext::getIntegerRank(const Type *T) const { /// promotion occurs. QualType ASTContext::isPromotableBitField(Expr *E) const { if (E->isTypeDependent() || E->isValueDependent()) - return QualType(); + return {}; // FIXME: We should not do this unless E->refersToBitField() is true. This // matters in C where getSourceBitField() will find bit-fields for various @@ -5419,7 +5403,7 @@ QualType ASTContext::isPromotableBitField(Expr *E) const { FieldDecl *Field = E->getSourceBitField(); // FIXME: conditional bit-fields? if (!Field) - return QualType(); + return {}; QualType FT = Field->getType(); @@ -5450,7 +5434,7 @@ QualType ASTContext::isPromotableBitField(Expr *E) const { // deliberately do not follow (GCC follows a pre-standard resolution to // C's DR315 which treats bit-width as being part of the type, and this leaks // into their semantics in some cases). - return QualType(); + return {}; } /// getPromotedIntegerType - Returns the type that Promotable will @@ -5459,10 +5443,10 @@ QualType ASTContext::isPromotableBitField(Expr *E) const { QualType ASTContext::getPromotedIntegerType(QualType Promotable) const { assert(!Promotable.isNull()); assert(Promotable->isPromotableIntegerType()); - if (const EnumType *ET = Promotable->getAs()) + if (const auto *ET = Promotable->getAs()) return ET->getDecl()->getPromotionType(); - if (const BuiltinType *BT = Promotable->getAs()) { + if (const auto *BT = Promotable->getAs()) { // C++ [conv.prom]: A prvalue of type char16_t, char32_t, or wchar_t // (3.9.1) can be converted to a prvalue of the first of the following // types that can represent all the values of its underlying type: @@ -5505,9 +5489,9 @@ Qualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const { return T.getObjCLifetime(); if (T->isArrayType()) T = getBaseElementType(T); - else if (const PointerType *PT = T->getAs()) + else if (const auto *PT = T->getAs()) T = PT->getPointeeType(); - else if (const ReferenceType *RT = T->getAs()) + else if (const auto *RT = T->getAs()) T = RT->getPointeeType(); else break; @@ -5532,9 +5516,9 @@ int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { const Type *RHSC = getCanonicalType(RHS).getTypePtr(); // Unwrap enums to their underlying type. - if (const EnumType *ET = dyn_cast(LHSC)) + if (const auto *ET = dyn_cast(LHSC)) LHSC = getIntegerTypeForEnum(ET); - if (const EnumType *ET = dyn_cast(RHSC)) + if (const auto *ET = dyn_cast(RHSC)) RHSC = getIntegerTypeForEnum(ET); if (LHSC == RHSC) return 0; @@ -5641,10 +5625,10 @@ QualType ASTContext::getObjCSuperType() const { } void ASTContext::setCFConstantStringType(QualType T) { - const TypedefType *TD = T->getAs(); + const auto *TD = T->getAs(); assert(TD && "Invalid CFConstantStringType"); CFConstantStringTypeDecl = cast(TD->getDecl()); - auto TagType = + const auto *TagType = CFConstantStringTypeDecl->getUnderlyingType()->getAs(); assert(TagType && "Invalid CFConstantStringType"); CFConstantStringTagDecl = TagType->getDecl(); @@ -5725,7 +5709,7 @@ QualType ASTContext::getBlockDescriptorExtendedType() const { } TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const { - auto BT = dyn_cast(T); + const auto *BT = dyn_cast(T); if (!BT) { if (isa(T)) @@ -5839,7 +5823,7 @@ TypedefDecl *ASTContext::getObjCInstanceTypeDecl() { // This returns true if a type has been typedefed to BOOL: // typedef BOOL; static bool isTypeTypedefedAsBOOL(QualType T) { - if (const TypedefType *TT = dyn_cast(T)) + if (const auto *TT = dyn_cast(T)) if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) return II->isStr("BOOL"); @@ -5891,8 +5875,7 @@ ASTContext::getInlineVariableDefinitionKind(const VarDecl *VD) const { return InlineVariableDefinitionKind::WeakUnknown; } -static inline -std::string charUnitsToString(const CharUnits &CU) { +static std::string charUnitsToString(const CharUnits &CU) { return llvm::itostr(CU.getQuantity()); } @@ -5933,8 +5916,8 @@ std::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const { ParmOffset = PtrSize; for (auto PVDecl : Decl->parameters()) { QualType PType = PVDecl->getOriginalType(); - if (const ArrayType *AT = - dyn_cast(PType->getCanonicalTypeInternal())) { + if (const auto *AT = + dyn_cast(PType->getCanonicalTypeInternal())) { // Use array's original type only if it has known number of // elements. if (!isa(AT)) @@ -5976,8 +5959,8 @@ ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const { // Argument types. for (auto PVDecl : Decl->parameters()) { QualType PType = PVDecl->getOriginalType(); - if (const ArrayType *AT = - dyn_cast(PType->getCanonicalTypeInternal())) { + if (const auto *AT = + dyn_cast(PType->getCanonicalTypeInternal())) { // Use array's original type only if it has known number of // elements. if (!isa(AT)) @@ -6046,8 +6029,8 @@ std::string ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, E = Decl->sel_param_end(); PI != E; ++PI) { const ParmVarDecl *PVDecl = *PI; QualType PType = PVDecl->getOriginalType(); - if (const ArrayType *AT = - dyn_cast(PType->getCanonicalTypeInternal())) { + if (const auto *AT = + dyn_cast(PType->getCanonicalTypeInternal())) { // Use array's original type only if it has known number of // elements. if (!isa(AT)) @@ -6069,13 +6052,12 @@ ASTContext::getObjCPropertyImplDeclForPropertyDecl( const Decl *Container) const { if (!Container) return nullptr; - if (const ObjCCategoryImplDecl *CID = - dyn_cast(Container)) { + if (const auto *CID = dyn_cast(Container)) { for (auto *PID : CID->property_impls()) if (PID->getPropertyDecl() == PD) return PID; } else { - const ObjCImplementationDecl *OID=cast(Container); + const auto *OID = cast(Container); for (auto *PID : OID->property_impls()) if (PID->getPropertyDecl() == PD) return PID; @@ -6182,7 +6164,7 @@ ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, /// 'i' or 'I' instead if encoding a struct field, or a pointer! void ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { if (isa(PointeeTy.getTypePtr())) { - if (const BuiltinType *BT = PointeeTy->getAs()) { + if (const auto *BT = PointeeTy->getAs()) { if (BT->getKind() == BuiltinType::ULong && getIntWidth(PointeeTy) == 32) PointeeTy = UnsignedIntTy; else @@ -6282,7 +6264,7 @@ static char ObjCEncodingForEnumType(const ASTContext *C, const EnumType *ET) { return 'i'; // The encoding of a fixed enum type matches its fixed underlying type. - const BuiltinType *BT = Enum->getIntegerType()->castAs(); + const auto *BT = Enum->getIntegerType()->castAs(); return getObjCEncodingForPrimitiveKind(C, BT->getKind()); } @@ -6319,10 +6301,10 @@ static void EncodeBitField(const ASTContext *Ctx, std::string& S, S += llvm::utostr(Offset); - if (const EnumType *ET = T->getAs()) + if (const auto *ET = T->getAs()) S += ObjCEncodingForEnumType(Ctx, ET); else { - const BuiltinType *BT = T->castAs(); + const auto *BT = T->castAs(); S += getObjCEncodingForPrimitiveKind(Ctx, BT->getKind()); } } @@ -6347,21 +6329,21 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, case Type::Enum: if (FD && FD->isBitField()) return EncodeBitField(this, S, T, FD); - if (const BuiltinType *BT = dyn_cast(CT)) + if (const auto *BT = dyn_cast(CT)) S += getObjCEncodingForPrimitiveKind(this, BT->getKind()); else S += ObjCEncodingForEnumType(this, cast(CT)); return; case Type::Complex: { - const ComplexType *CT = T->castAs(); + const auto *CT = T->castAs(); S += 'j'; getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, nullptr); return; } case Type::Atomic: { - const AtomicType *AT = T->castAs(); + const auto *AT = T->castAs(); S += 'A'; getObjCEncodingForTypeImpl(AT->getValueType(), S, false, false, nullptr); return; @@ -6373,7 +6355,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, case Type::RValueReference: { QualType PointeeTy; if (isa(CT)) { - const PointerType *PT = T->castAs(); + const auto *PT = T->castAs(); if (PT->isObjCSelType()) { S += ':'; return; @@ -6417,7 +6399,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, S += '*'; return; } - } else if (const RecordType *RTy = PointeeTy->getAs()) { + } else if (const auto *RTy = PointeeTy->getAs()) { // GCC binary compat: Need to convert "struct objc_class *" to "#". if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { S += '#'; @@ -6442,7 +6424,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, case Type::ConstantArray: case Type::IncompleteArray: case Type::VariableArray: { - const ArrayType *AT = cast(CT); + const auto *AT = cast(CT); if (isa(AT) && !StructField) { // Incomplete arrays are encoded as a pointer to the array element. @@ -6453,7 +6435,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, } else { S += '['; - if (const ConstantArrayType *CAT = dyn_cast(AT)) + if (const auto *CAT = dyn_cast(AT)) S += llvm::utostr(CAT->getSize().getZExtValue()); else { //Variable length arrays are encoded as a regular array with 0 elements. @@ -6482,8 +6464,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, // Anonymous structures print as '?' if (const IdentifierInfo *II = RDecl->getIdentifier()) { S += II->getName(); - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(RDecl)) { + if (const auto *Spec = dyn_cast(RDecl)) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); llvm::raw_string_ostream OS(S); printTemplateArgumentList(OS, TemplateArgs.asArray(), @@ -6525,10 +6506,10 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, } case Type::BlockPointer: { - const BlockPointerType *BT = T->castAs(); + const auto *BT = T->castAs(); S += "@?"; // Unlike a pointer-to-function, which is "^?". if (EncodeBlockParameters) { - const FunctionType *FT = BT->getPointeeType()->castAs(); + const auto *FT = BT->getPointeeType()->castAs(); S += '<'; // Block return type @@ -6540,7 +6521,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, // Block self S += "@?"; // Block parameters - if (const FunctionProtoType *FPT = dyn_cast(FT)) { + if (const auto *FPT = dyn_cast(FT)) { for (const auto &I : FPT->param_types()) getObjCEncodingForTypeImpl( I, S, ExpandPointedToStructures, ExpandStructures, FD, @@ -6594,7 +6575,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, } case Type::ObjCObjectPointer: { - const ObjCObjectPointerType *OPT = T->castAs(); + const auto *OPT = T->castAs(); if (OPT->isObjCIdType()) { S += '@'; return; @@ -6714,7 +6695,7 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, if (!RDecl->getDefinition() || RDecl->getDefinition()->isInvalidDecl()) return; - CXXRecordDecl *CXXRec = dyn_cast(RDecl); + const auto *CXXRec = dyn_cast(RDecl); std::multimap FieldOrBaseOffsets; const ASTRecordLayout &layout = getASTRecordLayout(RDecl); @@ -6807,7 +6788,7 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, if (!dcl) break; // reached end of structure. - if (CXXRecordDecl *base = dyn_cast(dcl)) { + if (auto *base = dyn_cast(dcl)) { // We expand the bases without their virtual bases since those are going // in the initial structure. Note that this differs from gcc which // expands virtual bases each time one is encountered in the hierarchy, @@ -6819,7 +6800,7 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize()); #endif } else { - FieldDecl *field = cast(dcl); + const auto *field = cast(dcl); if (FD) { S += '"'; S += field->getNameAsString(); @@ -7279,7 +7260,7 @@ ASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin, void *memory = Allocate(sizeof(OverloadedTemplateStorage) + size * sizeof(FunctionTemplateDecl*)); - OverloadedTemplateStorage *OT = new(memory) OverloadedTemplateStorage(size); + auto *OT = new (memory) OverloadedTemplateStorage(size); NamedDecl **Storage = OT->getStorage(); for (UnresolvedSetIterator I = Begin; I != End; ++I) { @@ -7411,7 +7392,7 @@ ASTContext::getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, TemplateName ASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const { - ASTContext &Self = const_cast(*this); + auto &Self = const_cast(*this); llvm::FoldingSetNodeID ID; SubstTemplateTemplateParmPackStorage::Profile(ID, Self, Param, ArgPack); @@ -7434,7 +7415,7 @@ ASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, /// is actually a value of type @c TargetInfo::IntType. CanQualType ASTContext::getFromTargetType(unsigned Type) const { switch (Type) { - case TargetInfo::NoInt: return CanQualType(); + case TargetInfo::NoInt: return {}; case TargetInfo::SignedChar: return SignedCharTy; case TargetInfo::UnsignedChar: return UnsignedCharTy; case TargetInfo::SignedShort: return ShortTy; @@ -7477,7 +7458,7 @@ Qualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const { // pointer. #ifndef NDEBUG QualType CT = Ty->getCanonicalTypeInternal(); - while (const ArrayType *AT = dyn_cast(CT)) + while (const auto *AT = dyn_cast(CT)) CT = AT->getElementType(); assert(CT->isAnyPointerType() || CT->isBlockPointerType()); #endif @@ -7508,8 +7489,8 @@ bool ASTContext::areCompatibleVectorTypes(QualType FirstVec, // Treat Neon vector types and most AltiVec vector types as if they are the // equivalent GCC vector types. - const VectorType *First = FirstVec->getAs(); - const VectorType *Second = SecondVec->getAs(); + const auto *First = FirstVec->getAs(); + const auto *Second = SecondVec->getAs(); if (First->getNumElements() == Second->getNumElements() && hasSameType(First->getElementType(), Second->getElementType()) && First->getVectorKind() != VectorType::AltiVecPixel && @@ -7542,8 +7523,8 @@ ASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, /// Class. bool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, QualType rhs) { - const ObjCObjectPointerType *lhsQID = lhs->getAs(); - const ObjCObjectPointerType *rhsOPT = rhs->getAs(); + const auto *lhsQID = lhs->getAs(); + const auto *rhsOPT = rhs->getAs(); assert((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible"); for (auto *lhsProto : lhsQID->quals()) { @@ -7573,7 +7554,7 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, return true; if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { - const ObjCObjectPointerType *rhsOPT = rhs->getAs(); + const auto *rhsOPT = rhs->getAs(); if (!rhsOPT) return false; @@ -7859,14 +7840,14 @@ void getIntersectionOfProtocols(ASTContext &Context, static bool canAssignObjCObjectTypes(ASTContext &ctx, QualType lhs, QualType rhs) { // Common case: two object pointers. - const ObjCObjectPointerType *lhsOPT = lhs->getAs(); - const ObjCObjectPointerType *rhsOPT = rhs->getAs(); + const auto *lhsOPT = lhs->getAs(); + const auto *rhsOPT = rhs->getAs(); if (lhsOPT && rhsOPT) return ctx.canAssignObjCInterfaces(lhsOPT, rhsOPT); // Two block pointers. - const BlockPointerType *lhsBlock = lhs->getAs(); - const BlockPointerType *rhsBlock = rhs->getAs(); + const auto *lhsBlock = lhs->getAs(); + const auto *rhsBlock = rhs->getAs(); if (lhsBlock && rhsBlock) return ctx.typesAreBlockPointerCompatible(lhs, rhs); @@ -7926,7 +7907,7 @@ QualType ASTContext::areCommonBaseCompatible( const ObjCInterfaceDecl* RDecl = RHS->getInterface(); if (!LDecl || !RDecl) - return QualType(); + return {}; // When either LHS or RHS is a kindof type, we should return a kindof type. // For example, for common base of kindof(ASub1) and kindof(ASub2), we return @@ -7951,7 +7932,7 @@ QualType ASTContext::areCommonBaseCompatible( if (!sameObjCTypeArgs(*this, LHS->getInterface(), LHS->getTypeArgs(), RHS->getTypeArgs(), /*stripKindOf=*/true)) - return QualType(); + return {}; } else if (LHS->isSpecialized() != RHS->isSpecialized()) { // If only one has type arguments, the result will not have type // arguments. @@ -8002,7 +7983,7 @@ QualType ASTContext::areCommonBaseCompatible( if (!sameObjCTypeArgs(*this, LHS->getInterface(), LHS->getTypeArgs(), RHS->getTypeArgs(), /*stripKindOf=*/true)) - return QualType(); + return {}; } else if (LHS->isSpecialized() != RHS->isSpecialized()) { // If only one has type arguments, the result will not have type // arguments. @@ -8037,7 +8018,7 @@ QualType ASTContext::areCommonBaseCompatible( RHS = RHSSuperType->castAs(); } - return QualType(); + return {}; } bool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, @@ -8104,8 +8085,8 @@ bool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { // get the "pointed to" types - const ObjCObjectPointerType *LHSOPT = LHS->getAs(); - const ObjCObjectPointerType *RHSOPT = RHS->getAs(); + const auto *LHSOPT = LHS->getAs(); + const auto *RHSOPT = RHS->getAs(); if (!LHSOPT || !RHSOPT) return false; @@ -8158,7 +8139,7 @@ QualType ASTContext::mergeTransparentUnionType(QualType T, QualType SubType, } } - return QualType(); + return {}; } /// mergeFunctionParameterTypes - merge two types which appear as function @@ -8185,10 +8166,10 @@ QualType ASTContext::mergeFunctionParameterTypes(QualType lhs, QualType rhs, QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, bool OfBlockPointer, bool Unqualified) { - const FunctionType *lbase = lhs->getAs(); - const FunctionType *rbase = rhs->getAs(); - const FunctionProtoType *lproto = dyn_cast(lbase); - const FunctionProtoType *rproto = dyn_cast(rbase); + const auto *lbase = lhs->getAs(); + const auto *rbase = rhs->getAs(); + const auto *lproto = dyn_cast(lbase); + const auto *rproto = dyn_cast(rbase); bool allLTypes = true; bool allRTypes = true; @@ -8205,7 +8186,8 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, else retType = mergeTypes(lbase->getReturnType(), rbase->getReturnType(), false, Unqualified); - if (retType.isNull()) return QualType(); + if (retType.isNull()) + return {}; if (Unqualified) retType = retType.getUnqualifiedType(); @@ -8231,20 +8213,20 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, // Compatible functions must have compatible calling conventions if (lbaseInfo.getCC() != rbaseInfo.getCC()) - return QualType(); + return {}; // Regparm is part of the calling convention. if (lbaseInfo.getHasRegParm() != rbaseInfo.getHasRegParm()) - return QualType(); + return {}; if (lbaseInfo.getRegParm() != rbaseInfo.getRegParm()) - return QualType(); + return {}; if (lbaseInfo.getProducesResult() != rbaseInfo.getProducesResult()) - return QualType(); + return {}; if (lbaseInfo.getNoCallerSavedRegs() != rbaseInfo.getNoCallerSavedRegs()) - return QualType(); + return {}; if (lbaseInfo.getNoCfCheck() != rbaseInfo.getNoCfCheck()) - return QualType(); + return {}; // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'. bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn(); @@ -8261,20 +8243,20 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, "C++ shouldn't be here"); // Compatible functions must have the same number of parameters if (lproto->getNumParams() != rproto->getNumParams()) - return QualType(); + return {}; // Variadic and non-variadic functions aren't compatible if (lproto->isVariadic() != rproto->isVariadic()) - return QualType(); + return {}; if (lproto->getTypeQuals() != rproto->getTypeQuals()) - return QualType(); + return {}; SmallVector newParamInfos; bool canUseLeft, canUseRight; if (!mergeExtParameterInfo(lproto, rproto, canUseLeft, canUseRight, newParamInfos)) - return QualType(); + return {}; if (!canUseLeft) allLTypes = false; @@ -8289,7 +8271,7 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, QualType paramType = mergeFunctionParameterTypes( lParamType, rParamType, OfBlockPointer, Unqualified); if (paramType.isNull()) - return QualType(); + return {}; if (Unqualified) paramType = paramType.getUnqualifiedType(); @@ -8322,7 +8304,8 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, const FunctionProtoType *proto = lproto ? lproto : rproto; if (proto) { assert(!proto->hasExceptionSpec() && "C++ shouldn't be here"); - if (proto->isVariadic()) return QualType(); + if (proto->isVariadic()) + return {}; // Check that the types are compatible with the types that // would result from default argument promotions (C99 6.7.5.3p15). // The only types actually affected are promotable integer @@ -8333,15 +8316,15 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, // Look at the converted type of enum types, since that is the type used // to pass enum values. - if (const EnumType *Enum = paramTy->getAs()) { + if (const auto *Enum = paramTy->getAs()) { paramTy = Enum->getDecl()->getIntegerType(); if (paramTy.isNull()) - return QualType(); + return {}; } if (paramTy->isPromotableIntegerType() || getCanonicalType(paramTy).getUnqualifiedType() == FloatTy) - return QualType(); + return {}; } if (allLTypes) return lhs; @@ -8365,7 +8348,8 @@ static QualType mergeEnumWithInteger(ASTContext &Context, const EnumType *ET, // Compatibility is based on the underlying type, not the promotion // type. QualType underlyingType = ET->getDecl()->getIntegerType(); - if (underlyingType.isNull()) return QualType(); + if (underlyingType.isNull()) + return {}; if (Context.hasSameType(underlyingType, other)) return other; @@ -8375,7 +8359,7 @@ static QualType mergeEnumWithInteger(ASTContext &Context, const EnumType *ET, Context.getTypeSize(underlyingType) == Context.getTypeSize(other)) return other; - return QualType(); + return {}; } QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, @@ -8411,7 +8395,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, LQuals.getAddressSpace() != RQuals.getAddressSpace() || LQuals.getObjCLifetime() != RQuals.getObjCLifetime() || LQuals.hasUnaligned() != RQuals.hasUnaligned()) - return QualType(); + return {}; // Exactly one GC qualifier difference is allowed: __strong is // okay if the other type has no GC qualifier but is an Objective @@ -8423,7 +8407,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) - return QualType(); + return {}; if (GC_L == Qualifiers::Strong && RHSCan->isObjCObjectPointerType()) { return mergeTypes(LHS, getObjCGCQualType(RHS, Qualifiers::Strong)); @@ -8431,7 +8415,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, if (GC_R == Qualifiers::Strong && LHSCan->isObjCObjectPointerType()) { return mergeTypes(getObjCGCQualType(LHS, Qualifiers::Strong), RHS); } - return QualType(); + return {}; } // Okay, qualifiers are equal. @@ -8462,7 +8446,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, if (LHSClass != RHSClass) { // Note that we only have special rules for turning block enum // returns into block int returns, not vice-versa. - if (const EnumType* ETy = LHS->getAs()) { + if (const auto *ETy = LHS->getAs()) { return mergeEnumWithInteger(*this, ETy, RHS, false); } if (const EnumType* ETy = RHS->getAs()) { @@ -8476,7 +8460,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, return RHS; } - return QualType(); + return {}; } // The canonical type classes match. @@ -8514,7 +8498,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, } QualType ResultType = mergeTypes(LHSPointee, RHSPointee, false, Unqualified); - if (ResultType.isNull()) return QualType(); + if (ResultType.isNull()) + return {}; if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) return LHS; if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) @@ -8536,7 +8521,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, // Blocks can't be an expression in a ternary operator (OpenCL v2.0 // 6.12.5) thus the following check is asymmetric. if (!LHSPteeQual.isAddressSpaceSupersetOf(RHSPteeQual)) - return QualType(); + return {}; LHSPteeQual.removeAddressSpace(); RHSPteeQual.removeAddressSpace(); LHSPointee = @@ -8546,7 +8531,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, } QualType ResultType = mergeTypes(LHSPointee, RHSPointee, OfBlockPointer, Unqualified); - if (ResultType.isNull()) return QualType(); + if (ResultType.isNull()) + return {}; if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) return LHS; if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) @@ -8564,7 +8550,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, } QualType ResultType = mergeTypes(LHSValue, RHSValue, false, Unqualified); - if (ResultType.isNull()) return QualType(); + if (ResultType.isNull()) + return {}; if (getCanonicalType(LHSValue) == getCanonicalType(ResultType)) return LHS; if (getCanonicalType(RHSValue) == getCanonicalType(ResultType)) @@ -8576,7 +8563,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) - return QualType(); + return {}; QualType LHSElem = getAsArrayType(LHS)->getElementType(); QualType RHSElem = getAsArrayType(RHS)->getElementType(); @@ -8586,7 +8573,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, } QualType ResultType = mergeTypes(LHSElem, RHSElem, false, Unqualified); - if (ResultType.isNull()) return QualType(); + if (ResultType.isNull()) + return {}; if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) @@ -8622,29 +8610,29 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, return mergeFunctionTypes(LHS, RHS, OfBlockPointer, Unqualified); case Type::Record: case Type::Enum: - return QualType(); + return {}; case Type::Builtin: // Only exactly equal builtin types are compatible, which is tested above. - return QualType(); + return {}; case Type::Complex: // Distinct complex types are incompatible. - return QualType(); + return {}; case Type::Vector: // FIXME: The merged type should be an ExtVector! if (areCompatVectorTypes(LHSCan->getAs(), RHSCan->getAs())) return LHS; - return QualType(); + return {}; case Type::ObjCObject: { // Check if the types are assignment compatible. // FIXME: This should be type compatibility, e.g. whether // "LHS x; RHS x;" at global scope is legal. - const ObjCObjectType* LHSIface = LHS->getAs(); - const ObjCObjectType* RHSIface = RHS->getAs(); + const auto *LHSIface = LHS->getAs(); + const auto *RHSIface = RHS->getAs(); if (canAssignObjCInterfaces(LHSIface, RHSIface)) return LHS; - return QualType(); + return {}; } case Type::ObjCObjectPointer: if (OfBlockPointer) { @@ -8653,17 +8641,17 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, RHS->getAs(), BlockReturnType)) return LHS; - return QualType(); + return {}; } if (canAssignObjCInterfaces(LHS->getAs(), RHS->getAs())) return LHS; - return QualType(); + return {}; case Type::Pipe: assert(LHS != RHS && "Equivalent pipe types should have already been handled!"); - return QualType(); + return {}; } llvm_unreachable("Invalid Type::Class!"); @@ -8731,7 +8719,7 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { return LHS; if (RHSCan->isFunctionType()) { if (!LHSCan->isFunctionType()) - return QualType(); + return {}; QualType OldReturnType = cast(RHSCan.getTypePtr())->getReturnType(); QualType NewReturnType = @@ -8739,12 +8727,12 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { QualType ResReturnType = mergeObjCGCQualifiers(NewReturnType, OldReturnType); if (ResReturnType.isNull()) - return QualType(); + return {}; if (ResReturnType == NewReturnType || ResReturnType == OldReturnType) { // id foo(); ... __strong id foo(); or: __strong id foo(); ... id foo(); // In either case, use OldReturnType to build the new function type. - const FunctionType *F = LHS->getAs(); - if (const FunctionProtoType *FPT = cast(F)) { + const auto *F = LHS->getAs(); + if (const auto *FPT = cast(F)) { FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); EPI.ExtInfo = getFunctionExtInfo(LHS); QualType ResultType = @@ -8752,7 +8740,7 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { return ResultType; } } - return QualType(); + return {}; } // If the qualifiers are different, the types can still be merged. @@ -8762,7 +8750,7 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { // If any of these qualifiers are different, we have a type mismatch. if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || LQuals.getAddressSpace() != RQuals.getAddressSpace()) - return QualType(); + return {}; // Exactly one GC qualifier difference is allowed: __strong is // okay if the other type has no GC qualifier but is an Objective @@ -8774,13 +8762,13 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) - return QualType(); + return {}; if (GC_L == Qualifiers::Strong) return LHS; if (GC_R == Qualifiers::Strong) return RHS; - return QualType(); + return {}; } if (LHSCan->isObjCObjectPointerType() && RHSCan->isObjCObjectPointerType()) { @@ -8792,7 +8780,7 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { if (ResQT == RHSBaseQT) return RHS; } - return QualType(); + return {}; } //===----------------------------------------------------------------------===// @@ -8800,7 +8788,7 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { //===----------------------------------------------------------------------===// unsigned ASTContext::getIntWidth(QualType T) const { - if (const EnumType *ET = T->getAs()) + if (const auto *ET = T->getAs()) T = ET->getDecl()->getIntegerType(); if (T->isBooleanType()) return 1; @@ -8812,15 +8800,15 @@ QualType ASTContext::getCorrespondingUnsignedType(QualType T) const { assert(T->hasSignedIntegerRepresentation() && "Unexpected type"); // Turn <4 x signed int> -> <4 x unsigned int> - if (const VectorType *VTy = T->getAs()) + if (const auto *VTy = T->getAs()) return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), VTy->getNumElements(), VTy->getVectorKind()); // For enums, we return the unsigned version of the base type. - if (const EnumType *ETy = T->getAs()) + if (const auto *ETy = T->getAs()) T = ETy->getDecl()->getIntegerType(); - const BuiltinType *BTy = T->getAs(); + const auto *BTy = T->getAs(); assert(BTy && "Unexpected signed integer type"); switch (BTy->getKind()) { case BuiltinType::Char_S: @@ -9066,7 +9054,7 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, Type = Context.getFILEType(); if (Type.isNull()) { Error = ASTContext::GE_Missing_stdio; - return QualType(); + return {}; } break; case 'J': @@ -9077,7 +9065,7 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, if (Type.isNull()) { Error = ASTContext::GE_Missing_setjmp; - return QualType(); + return {}; } break; case 'K': @@ -9086,7 +9074,7 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, if (Type.isNull()) { Error = ASTContext::GE_Missing_ucontext; - return QualType(); + return {}; } break; case 'p': @@ -9148,14 +9136,14 @@ QualType ASTContext::GetBuiltinType(unsigned Id, QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error, RequiresICE, true); if (Error != GE_None) - return QualType(); + return {}; assert(!RequiresICE && "Result of intrinsic cannot be required to be an ICE"); while (TypeStr[0] && TypeStr[0] != '.') { QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error, RequiresICE, true); if (Error != GE_None) - return QualType(); + return {}; // If this argument is required to be an IntegerConstantExpression and the // caller cares, fill in the bitmask we return. @@ -9170,7 +9158,7 @@ QualType ASTContext::GetBuiltinType(unsigned Id, } if (Id == Builtin::BI__GetExceptionInfo) - return QualType(); + return {}; assert((TypeStr[0] != '.' || TypeStr[1] == 0) && "'.' should only occur at end of builtin type list!"); @@ -9201,7 +9189,7 @@ static GVALinkage basicGVALinkageForFunction(const ASTContext &Context, // Non-user-provided functions get emitted as weak definitions with every // use, no matter whether they've been explicitly instantiated etc. - if (auto *MD = dyn_cast(FD)) + if (const auto *MD = dyn_cast(FD)) if (!MD->isUserProvided()) return GVA_DiscardableODR; @@ -9391,7 +9379,7 @@ GVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { } bool ASTContext::DeclMustBeEmitted(const Decl *D) { - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (!VD->isFileVarDecl()) return false; // Global named register variables (GNU extension) are never emitted. @@ -9400,7 +9388,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { if (VD->getDescribedVarTemplate() || isa(VD)) return false; - } else if (const FunctionDecl *FD = dyn_cast(D)) { + } else if (const auto *FD = dyn_cast(D)) { // We never need to emit an uninstantiated function template. if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) return false; @@ -9431,7 +9419,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { if (D->hasAttr() || D->hasAttr()) return true; - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // Forward declarations aren't required. if (!FD->doesThisDeclarationHaveABody()) return FD->doesDeclarationForceExternallyVisibleDefinition(); @@ -9443,7 +9431,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { // The key function for a class is required. This rule only comes // into play when inline functions can be key functions, though. if (getTargetInfo().getCXXABI().canKeyFunctionBeInline()) { - if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (const auto *MD = dyn_cast(FD)) { const CXXRecordDecl *RD = MD->getParent(); if (MD->isOutOfLine() && RD->isDynamicClass()) { const CXXMethodDecl *KeyFunc = getCurrentKeyFunction(RD); @@ -9461,7 +9449,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { return !isDiscardableGVALinkage(Linkage); } - const VarDecl *VD = cast(D); + const auto *VD = cast(D); assert(VD->isFileVarDecl() && "Expected file scoped var"); if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly && @@ -9489,9 +9477,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { // Likewise, variables with tuple-like bindings are required if their // bindings have side-effects. - if (auto *DD = dyn_cast(VD)) - for (auto *BD : DD->bindings()) - if (auto *BindingVD = BD->getHoldingVar()) + if (const auto *DD = dyn_cast(VD)) + for (const auto *BD : DD->bindings()) + if (const auto *BindingVD = BD->getHoldingVar()) if (DeclMustBeEmitted(BindingVD)) return true; @@ -9636,7 +9624,7 @@ QualType ASTContext::getRealTypeForBitwidth(unsigned DestWidth) const { case TargetInfo::Float128: return Float128Ty; case TargetInfo::NoFloat: - return QualType(); + return {}; } llvm_unreachable("Unhandled TargetInfo::RealType value"); @@ -9915,7 +9903,8 @@ static ASTContext::DynTypedNodeList getDynNodeFromMap(const NodeTy &Node, if (I == Map.end()) { return llvm::ArrayRef(); } - if (auto *V = I->second.template dyn_cast()) { + if (const auto *V = + I->second.template dyn_cast()) { return llvm::makeArrayRef(*V); } return getSingleDynTypedNodeFromParentMap(I->second); diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 45ecc1b5b1..736b9331e3 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -125,8 +125,8 @@ CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl, bool DelayTypeCreation) { - CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, - IdLoc, Id, PrevDecl); + auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, + PrevDecl); R->MayHaveOutOfDateDef = C.getLangOpts().Modules; // FIXME: DelayTypeCreation seems like such a hack @@ -140,9 +140,8 @@ CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, bool Dependent, bool IsGeneric, LambdaCaptureDefault CaptureDefault) { - CXXRecordDecl *R = - new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, - nullptr, nullptr); + auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, + nullptr, nullptr); R->IsBeingDefined = true; R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, @@ -155,7 +154,7 @@ CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, CXXRecordDecl * CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { - CXXRecordDecl *R = new (C, ID) CXXRecordDecl( + auto *R = new (C, ID) CXXRecordDecl( CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), nullptr, nullptr); R->MayHaveOutOfDateDef = false; @@ -198,8 +197,8 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, // Skip dependent types; we can't do any checking on them now. if (BaseType->isDependentType()) continue; - CXXRecordDecl *BaseClassDecl - = cast(BaseType->getAs()->getDecl()); + auto *BaseClassDecl = + cast(BaseType->getAs()->getDecl()); if (!BaseClassDecl->isEmpty()) { if (!data().Empty) { @@ -514,7 +513,7 @@ void CXXRecordDecl::addedMember(Decl *D) { if (D->getFriendObjectKind() || D->isInvalidDecl()) return; - FunctionTemplateDecl *FunTmpl = dyn_cast(D); + auto *FunTmpl = dyn_cast(D); if (FunTmpl) D = FunTmpl->getTemplatedDecl(); @@ -522,12 +521,11 @@ void CXXRecordDecl::addedMember(Decl *D) { Decl *DUnderlying = D; if (auto *ND = dyn_cast(DUnderlying)) { DUnderlying = ND->getUnderlyingDecl(); - if (FunctionTemplateDecl *UnderlyingFunTmpl = - dyn_cast(DUnderlying)) + if (auto *UnderlyingFunTmpl = dyn_cast(DUnderlying)) DUnderlying = UnderlyingFunTmpl->getTemplatedDecl(); } - if (CXXMethodDecl *Method = dyn_cast(D)) { + if (const auto *Method = dyn_cast(D)) { if (Method->isVirtual()) { // C++ [dcl.init.aggr]p1: // An aggregate is an array or a class with [...] no virtual functions. @@ -570,7 +568,7 @@ void CXXRecordDecl::addedMember(Decl *D) { unsigned SMKind = 0; // Handle constructors. - if (CXXConstructorDecl *Constructor = dyn_cast(D)) { + if (const auto *Constructor = dyn_cast(D)) { if (!Constructor->isImplicit()) { // Note that we have a user-declared constructor. data().UserDeclaredConstructor = true; @@ -612,8 +610,7 @@ void CXXRecordDecl::addedMember(Decl *D) { } // Handle constructors, including those inherited from base classes. - if (CXXConstructorDecl *Constructor = - dyn_cast(DUnderlying)) { + if (const auto *Constructor = dyn_cast(DUnderlying)) { // Record if we see any constexpr constructors which are neither copy // nor move constructors. // C++1z [basic.types]p10: @@ -625,7 +622,7 @@ void CXXRecordDecl::addedMember(Decl *D) { } // Handle destructors. - if (CXXDestructorDecl *DD = dyn_cast(D)) { + if (const auto *DD = dyn_cast(D)) { SMKind |= SMF_Destructor; if (DD->isUserProvided()) @@ -643,12 +640,12 @@ void CXXRecordDecl::addedMember(Decl *D) { } // Handle member functions. - if (CXXMethodDecl *Method = dyn_cast(D)) { + if (const auto *Method = dyn_cast(D)) { if (Method->isCopyAssignmentOperator()) { SMKind |= SMF_CopyAssignment; - const ReferenceType *ParamTy = - Method->getParamDecl(0)->getType()->getAs(); + const auto *ParamTy = + Method->getParamDecl(0)->getType()->getAs(); if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) data().HasDeclaredCopyAssignmentWithConstParam = true; } @@ -657,7 +654,7 @@ void CXXRecordDecl::addedMember(Decl *D) { SMKind |= SMF_MoveAssignment; // Keep the list of conversion functions up-to-date. - if (CXXConversionDecl *Conversion = dyn_cast(D)) { + if (auto *Conversion = dyn_cast(D)) { // FIXME: We use the 'unsafe' accessor for the access specifier here, // because Sema may not have set it yet. That's really just a misdesign // in Sema. However, LLDB *will* have set the access specifier correctly, @@ -736,7 +733,7 @@ void CXXRecordDecl::addedMember(Decl *D) { } // Handle non-static data members. - if (FieldDecl *Field = dyn_cast(D)) { + if (const auto *Field = dyn_cast(D)) { // C++ [class.bit]p2: // A declaration for a bit-field that omits the identifier declares an // unnamed bit-field. Unnamed bit-fields are not members and cannot be @@ -878,8 +875,8 @@ void CXXRecordDecl::addedMember(Decl *D) { if (T->isReferenceType()) data().DefaultedMoveAssignmentIsDeleted = true; - if (const RecordType *RecordTy = T->getAs()) { - CXXRecordDecl* FieldRec = cast(RecordTy->getDecl()); + if (const auto *RecordTy = T->getAs()) { + auto *FieldRec = cast(RecordTy->getDecl()); if (FieldRec->getDefinition()) { addedClassSubobject(FieldRec); @@ -1091,7 +1088,7 @@ void CXXRecordDecl::addedMember(Decl *D) { } // Handle using declarations of conversion functions. - if (UsingShadowDecl *Shadow = dyn_cast(D)) { + if (auto *Shadow = dyn_cast(D)) { if (Shadow->getDeclName().getNameKind() == DeclarationName::CXXConversionFunctionName) { ASTContext &Ctx = getASTContext(); @@ -1099,7 +1096,7 @@ void CXXRecordDecl::addedMember(Decl *D) { } } - if (UsingDecl *Using = dyn_cast(D)) { + if (const auto *Using = dyn_cast(D)) { if (Using->getDeclName().getNameKind() == DeclarationName::CXXConstructorName) { data().HasInheritedConstructor = true; @@ -1119,7 +1116,7 @@ void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { // The kind of special member this declaration is, if any. unsigned SMKind = 0; - if (CXXConstructorDecl *Constructor = dyn_cast(D)) { + if (const auto *Constructor = dyn_cast(D)) { if (Constructor->isDefaultConstructor()) { SMKind |= SMF_DefaultConstructor; if (Constructor->isConstexpr()) @@ -1152,7 +1149,7 @@ void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { void CXXRecordDecl::setTrivialForCallFlags(CXXMethodDecl *D) { unsigned SMKind = 0; - if (CXXConstructorDecl *Constructor = dyn_cast(D)) { + if (const auto *Constructor = dyn_cast(D)) { if (Constructor->isCopyConstructor()) SMKind = SMF_CopyConstructor; else if (Constructor->isMoveConstructor()) @@ -1191,8 +1188,7 @@ CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const { assert(Calls.size() == 1 && "More than one lambda call operator!"); NamedDecl *CallOp = Calls.front(); - if (FunctionTemplateDecl *CallOpTmpl = - dyn_cast(CallOp)) + if (const auto *CallOpTmpl = dyn_cast(CallOp)) return cast(CallOpTmpl->getTemplatedDecl()); return cast(CallOp); @@ -1206,8 +1202,7 @@ CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const { if (Invoker.empty()) return nullptr; assert(Invoker.size() == 1 && "More than one static invoker operator!"); NamedDecl *InvokerFun = Invoker.front(); - if (FunctionTemplateDecl *InvokerTemplate = - dyn_cast(InvokerFun)) + if (const auto *InvokerTemplate = dyn_cast(InvokerFun)) return cast(InvokerTemplate->getTemplatedDecl()); return cast(InvokerFun); @@ -1320,7 +1315,7 @@ static void CollectVisibleConversions(ASTContext &Context, = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); bool BaseInVirtual = InVirtual || I.isVirtual(); - CXXRecordDecl *Base = cast(RT->getDecl()); + auto *Base = cast(RT->getDecl()); CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, *HiddenTypes, Output, VOutput, HiddenVBaseCs); } @@ -1447,8 +1442,7 @@ void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) { } TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ - if (const ClassTemplateSpecializationDecl *Spec - = dyn_cast(this)) + if (const auto *Spec = dyn_cast(this)) return Spec->getSpecializationKind(); if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) @@ -1459,8 +1453,7 @@ TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ void CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(this)) { + if (auto *Spec = dyn_cast(this)) { Spec->setSpecializationKind(TSK); return; } @@ -1665,8 +1658,8 @@ bool CXXRecordDecl::mayBeAbstract() const { return false; for (const auto &B : bases()) { - CXXRecordDecl *BaseDecl - = cast(B.getType()->getAs()->getDecl()); + const auto *BaseDecl = + cast(B.getType()->getAs()->getDecl()); if (BaseDecl->isAbstract()) return true; } @@ -1733,7 +1726,7 @@ CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, } for (auto *ND : RD->lookup(getDeclName())) { - CXXMethodDecl *MD = dyn_cast(ND); + auto *MD = dyn_cast(ND); if (!MD) continue; if (recursivelyOverrides(MD, this)) @@ -1746,7 +1739,7 @@ CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, const RecordType *RT = I.getType()->getAs(); if (!RT) continue; - const CXXRecordDecl *Base = cast(RT->getDecl()); + const auto *Base = cast(RT->getDecl()); CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base); if (T) return T; @@ -1821,8 +1814,8 @@ CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base, if (BestDynamicDecl->hasAttr()) return DevirtualizedMethod; - if (const DeclRefExpr *DRE = dyn_cast(Base)) { - if (const VarDecl *VD = dyn_cast(DRE->getDecl())) + if (const auto *DRE = dyn_cast(Base)) { + if (const auto *VD = dyn_cast(DRE->getDecl())) if (VD->getType()->isRecordType()) // This is a record decl. We know the type and can devirtualize it. return DevirtualizedMethod; @@ -1833,7 +1826,7 @@ CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base, // We can devirtualize calls on an object accessed by a class member access // expression, since by C++11 [basic.life]p6 we know that it can't refer to // a derived class object constructed in the same location. - if (const MemberExpr *ME = dyn_cast(Base)) { + if (const auto *ME = dyn_cast(Base)) { const ValueDecl *VD = ME->getMemberDecl(); return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr; } @@ -1912,7 +1905,7 @@ bool CXXMethodDecl::isUsualDeallocationFunction() const { DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName()); for (DeclContext::lookup_result::iterator I = R.begin(), E = R.end(); I != E; ++I) { - if (const FunctionDecl *FD = dyn_cast(*I)) + if (const auto *FD = dyn_cast(*I)) if (FD->getNumParams() == 1) return false; } @@ -1932,7 +1925,7 @@ bool CXXMethodDecl::isCopyAssignmentOperator() const { return false; QualType ParamType = getParamDecl(0)->getType(); - if (const LValueReferenceType *Ref = ParamType->getAs()) + if (const auto *Ref = ParamType->getAs()) ParamType = Ref->getPointeeType(); ASTContext &Context = getASTContext(); @@ -2070,7 +2063,7 @@ TypeLoc CXXCtorInitializer::getBaseClassLoc() const { if (isBaseInitializer()) return Initializee.get()->getTypeLoc(); else - return TypeLoc(); + return {}; } const Type *CXXCtorInitializer::getBaseClass() const { @@ -2087,10 +2080,10 @@ SourceLocation CXXCtorInitializer::getSourceLocation() const { if (isAnyMemberInitializer()) return getMemberLocation(); - if (TypeSourceInfo *TSInfo = Initializee.get()) + if (const auto *TSInfo = Initializee.get()) return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); - return SourceLocation(); + return {}; } SourceRange CXXCtorInitializer::getSourceRange() const { @@ -2098,7 +2091,7 @@ SourceRange CXXCtorInitializer::getSourceRange() const { FieldDecl *D = getAnyMember(); if (Expr *I = D->getInClassInitializer()) return I->getSourceRange(); - return SourceRange(); + return {}; } return SourceRange(getSourceLocation(), getRParenLoc()); @@ -2142,7 +2135,7 @@ CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const { CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { assert(isDelegatingConstructor() && "Not a delegating constructor!"); Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); - if (CXXConstructExpr *Construct = dyn_cast(E)) + if (const auto *Construct = dyn_cast(E)) return Construct->getConstructor(); return nullptr; @@ -2188,7 +2181,7 @@ bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { const ParmVarDecl *Param = getParamDecl(0); // Do we have a reference type? - const ReferenceType *ParamRefType = Param->getType()->getAs(); + const auto *ParamRefType = Param->getType()->getAs(); if (!ParamRefType) return false; @@ -2335,7 +2328,7 @@ UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation IdentLoc, NamedDecl *Used, DeclContext *CommonAncestor) { - if (NamespaceDecl *NS = dyn_cast_or_null(Used)) + if (auto *NS = dyn_cast_or_null(Used)) Used = NS->getOriginalNamespace(); return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, IdentLoc, Used, CommonAncestor); @@ -2350,8 +2343,7 @@ UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C, } NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { - if (NamespaceAliasDecl *NA = - dyn_cast_or_null(NominatedNamespace)) + if (auto *NA = dyn_cast_or_null(NominatedNamespace)) return NA->getNamespace(); return cast_or_null(NominatedNamespace); } @@ -2431,7 +2423,7 @@ NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation IdentLoc, NamedDecl *Namespace) { // FIXME: Preserve the aliased namespace as written. - if (NamespaceDecl *NS = dyn_cast_or_null(Namespace)) + if (auto *NS = dyn_cast_or_null(Namespace)) Namespace = NS->getOriginalNamespace(); return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, QualifierLoc, IdentLoc, Namespace); @@ -2451,8 +2443,7 @@ UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, UsingDecl *Using, NamedDecl *Target) : NamedDecl(K, DC, Loc, Using ? Using->getDeclName() : DeclarationName()), - redeclarable_base(C), Underlying(), - UsingOrNextShadow(cast(Using)) { + redeclarable_base(C), UsingOrNextShadow(cast(Using)) { if (Target) setTargetDecl(Target); setImplicit(); @@ -2469,8 +2460,8 @@ UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { UsingDecl *UsingShadowDecl::getUsingDecl() const { const UsingShadowDecl *Shadow = this; - while (const UsingShadowDecl *NextShadow = - dyn_cast(Shadow->UsingOrNextShadow)) + while (const auto *NextShadow = + dyn_cast(Shadow->UsingOrNextShadow)) Shadow = NextShadow; return cast(Shadow->UsingOrNextShadow); } @@ -2689,7 +2680,7 @@ DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C, void DecompositionDecl::printName(llvm::raw_ostream &os) const { os << '['; bool Comma = false; - for (auto *B : bindings()) { + for (const auto *B : bindings()) { if (Comma) os << ", "; B->printName(os); diff --git a/lib/AST/DeclFriend.cpp b/lib/AST/DeclFriend.cpp index 461bf36858..08fbed3615 100644 --- a/lib/AST/DeclFriend.cpp +++ b/lib/AST/DeclFriend.cpp @@ -39,7 +39,7 @@ FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, ArrayRef FriendTypeTPLists) { #ifndef NDEBUG if (Friend.is()) { - NamedDecl *D = Friend.get(); + const auto *D = Friend.get(); assert(isa(D) || isa(D) || isa(D) || @@ -57,8 +57,8 @@ FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, std::size_t Extra = FriendDecl::additionalSizeToAlloc( FriendTypeTPLists.size()); - FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL, - FriendTypeTPLists); + auto *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL, + FriendTypeTPLists); cast(DC)->pushFriendDecl(FD); return FD; } diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 982fd45849..be2a147d89 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -11,14 +11,15 @@ // //===----------------------------------------------------------------------===// +#include "clang/AST/Stmt.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclGroup.h" +#include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/ExprOpenMP.h" -#include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtOpenMP.h" @@ -154,11 +155,11 @@ Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) { const Stmt *Stmt::stripLabelLikeStatements() const { const Stmt *S = this; while (true) { - if (const LabelStmt *LS = dyn_cast(S)) + if (const auto *LS = dyn_cast(S)) S = LS->getSubStmt(); - else if (const SwitchCase *SC = dyn_cast(S)) + else if (const auto *SC = dyn_cast(S)) S = SC->getSubStmt(); - else if (const AttributedStmt *AS = dyn_cast(S)) + else if (const auto *AS = dyn_cast(S)) S = AS->getSubStmt(); else return S; @@ -173,14 +174,14 @@ namespace { // These silly little functions have to be static inline to suppress // unused warnings, and they have to be defined to suppress other // warnings. - static inline good is_good(good) { return good(); } + static good is_good(good) { return good(); } typedef Stmt::child_range children_t(); template good implements_children(children_t T::*) { return good(); } LLVM_ATTRIBUTE_UNUSED - static inline bad implements_children(children_t Stmt::*) { + static bad implements_children(children_t Stmt::*) { return bad(); } @@ -189,7 +190,7 @@ namespace { return good(); } LLVM_ATTRIBUTE_UNUSED - static inline bad implements_getLocStart(getLocStart_t Stmt::*) { + static bad implements_getLocStart(getLocStart_t Stmt::*) { return bad(); } @@ -198,7 +199,7 @@ namespace { return good(); } LLVM_ATTRIBUTE_UNUSED - static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { + static bad implements_getLocEnd(getLocEnd_t Stmt::*) { return bad(); } @@ -351,49 +352,49 @@ AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, } std::string AsmStmt::generateAsmString(const ASTContext &C) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->generateAsmString(C); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->generateAsmString(C); llvm_unreachable("unknown asm statement kind!"); } StringRef AsmStmt::getOutputConstraint(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getOutputConstraint(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getOutputConstraint(i); llvm_unreachable("unknown asm statement kind!"); } const Expr *AsmStmt::getOutputExpr(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getOutputExpr(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getOutputExpr(i); llvm_unreachable("unknown asm statement kind!"); } StringRef AsmStmt::getInputConstraint(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getInputConstraint(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getInputConstraint(i); llvm_unreachable("unknown asm statement kind!"); } const Expr *AsmStmt::getInputExpr(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getInputExpr(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getInputExpr(i); llvm_unreachable("unknown asm statement kind!"); } StringRef AsmStmt::getClobber(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getClobber(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getClobber(i); llvm_unreachable("unknown asm statement kind!"); } @@ -681,14 +682,14 @@ std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { AnalyzeAsmString(Pieces, C, DiagOffs); std::string AsmString; - for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { - if (Pieces[i].isString()) - AsmString += Pieces[i].getString(); - else if (Pieces[i].getModifier() == '\0') - AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); + for (const auto &Piece : Pieces) { + if (Piece.isString()) + AsmString += Piece.getString(); + else if (Piece.getModifier() == '\0') + AsmString += '$' + llvm::utostr(Piece.getOperandNo()); else - AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + - Pieces[i].getModifier() + '}'; + AsmString += "${" + llvm::utostr(Piece.getOperandNo()) + ':' + + Piece.getModifier() + '}'; } return AsmString; } @@ -804,7 +805,7 @@ VarDecl *IfStmt::getConditionVariable() const { if (!SubExprs[VAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[VAR]); + auto *DS = cast(SubExprs[VAR]); return cast(DS->getSingleDecl()); } @@ -839,7 +840,7 @@ VarDecl *ForStmt::getConditionVariable() const { if (!SubExprs[CONDVAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[CONDVAR]); + auto *DS = cast(SubExprs[CONDVAR]); return cast(DS->getSingleDecl()); } @@ -867,7 +868,7 @@ VarDecl *SwitchStmt::getConditionVariable() const { if (!SubExprs[VAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[VAR]); + auto *DS = cast(SubExprs[VAR]); return cast(DS->getSingleDecl()); } @@ -901,7 +902,7 @@ VarDecl *WhileStmt::getConditionVariable() const { if (!SubExprs[VAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[VAR]); + auto *DS = cast(SubExprs[VAR]); return cast(DS->getSingleDecl()); } @@ -918,8 +919,7 @@ void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { // IndirectGotoStmt LabelDecl *IndirectGotoStmt::getConstantTarget() { - if (AddrLabelExpr *E = - dyn_cast(getTarget()->IgnoreParenImpCasts())) + if (auto *E = dyn_cast(getTarget()->IgnoreParenImpCasts())) return E->getLabel(); return nullptr; }