From a204565a1d5376830ec8fa0efa9dfd7326ea89d6 Mon Sep 17 00:00:00 2001 From: Eugene Zelenko Date: Thu, 29 Mar 2018 20:51:59 +0000 Subject: [PATCH] [AST] Fix some Clang-tidy modernize-use-auto warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328826 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclTemplate.h | 59 +++--- include/clang/AST/Type.h | 69 ++++--- lib/AST/DeclTemplate.cpp | 56 +++--- lib/AST/Type.cpp | 330 +++++++++++++++---------------- 4 files changed, 249 insertions(+), 265 deletions(-) diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 7842d70971..9c68352e76 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -299,7 +299,7 @@ class DefaultArgStorage { static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); - if (auto *Prev = Storage.ValueOrInherited.template dyn_cast()) + if (auto *Prev = Storage.ValueOrInherited.template dyn_cast()) Parm = Prev; assert(!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && @@ -321,9 +321,9 @@ public: /// default argument is visible. ArgType get() const { const DefaultArgStorage *Storage = this; - if (auto *Prev = ValueOrInherited.template dyn_cast()) + if (const auto *Prev = ValueOrInherited.template dyn_cast()) Storage = &Prev->getDefaultArgStorage(); - if (auto *C = Storage->ValueOrInherited.template dyn_cast()) + if (const auto *C = Storage->ValueOrInherited.template dyn_cast()) return C->Value; return Storage->ValueOrInherited.template get(); } @@ -331,9 +331,9 @@ public: /// Get the parameter from which we inherit the default argument, if any. /// This is the parameter on which the default argument was actually written. const ParmDecl *getInheritedFrom() const { - if (auto *D = ValueOrInherited.template dyn_cast()) + if (const auto *D = ValueOrInherited.template dyn_cast()) return D; - if (auto *C = ValueOrInherited.template dyn_cast()) + if (const auto *C = ValueOrInherited.template dyn_cast()) return C->PrevDeclWithDefaultArg; return nullptr; } @@ -443,7 +443,7 @@ public: } Expr *getAssociatedConstraints() const { - const TemplateDecl *const C = cast(getCanonicalDecl()); + const auto *const C = cast(getCanonicalDecl()); const auto *const CTDI = C->TemplateParams.dyn_cast(); return CTDI ? CTDI->getAssociatedConstraints() : nullptr; @@ -466,6 +466,7 @@ public: protected: NamedDecl *TemplatedDecl; + /// \brief The template parameter list and optional requires-clause /// associated with this declaration; alternatively, a /// \c ConstrainedTemplateDeclInfo if the associated constraints of the @@ -1621,7 +1622,7 @@ public: } SourceRange getSourceRange() const override LLVM_READONLY { - return SourceRange(); + return {}; } BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; } @@ -1789,8 +1790,8 @@ public: llvm::PointerUnion getSpecializedTemplateOrPartial() const { - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) + if (const auto *PartialSpec = + SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization; return SpecializedTemplate.get(); @@ -1808,8 +1809,8 @@ public: /// deduced template arguments for the class template partial specialization /// itself. const TemplateArgumentList &getTemplateInstantiationArgs() const { - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) + if (const auto *PartialSpec = + SpecializedTemplate.dyn_cast()) return *PartialSpec->TemplateArgs; return getTemplateArgs(); @@ -1822,8 +1823,7 @@ public: const TemplateArgumentList *TemplateArgs) { assert(!SpecializedTemplate.is() && "Already set to a class template partial specialization!"); - SpecializedPartialSpecialization *PS - = new (getASTContext()) SpecializedPartialSpecialization(); + auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); PS->PartialSpecialization = PartialSpec; PS->TemplateArgs = TemplateArgs; SpecializedTemplate = PS; @@ -1984,7 +1984,7 @@ public: /// \c Outer::Inner, this function would return /// \c Outer::Inner. ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { - const ClassTemplatePartialSpecializationDecl *First = + const auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getPointer(); } @@ -1995,8 +1995,7 @@ public: void setInstantiatedFromMember( ClassTemplatePartialSpecializationDecl *PartialSpec) { - ClassTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); First->InstantiatedFromMember.setPointer(PartialSpec); } @@ -2017,15 +2016,14 @@ public: /// struct X::Inner { /* ... */ }; /// \endcode bool isMemberSpecialization() { - ClassTemplatePartialSpecializationDecl *First = + const auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getInt(); } /// \brief Note that this member template is a specialization. void setMemberSpecialization() { - ClassTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); assert(First->InstantiatedFromMember.getPointer() && "Only member templates can be member template specializations"); return First->InstantiatedFromMember.setInt(true); @@ -2627,7 +2625,7 @@ public: /// specialization which was specialized by this. llvm::PointerUnion getSpecializedTemplateOrPartial() const { - if (SpecializedPartialSpecialization *PartialSpec = + if (const auto *PartialSpec = SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization; @@ -2646,7 +2644,7 @@ public: /// return deduced template arguments for the variable template partial /// specialization itself. const TemplateArgumentList &getTemplateInstantiationArgs() const { - if (SpecializedPartialSpecialization *PartialSpec = + if (const auto *PartialSpec = SpecializedTemplate.dyn_cast()) return *PartialSpec->TemplateArgs; @@ -2660,8 +2658,7 @@ public: const TemplateArgumentList *TemplateArgs) { assert(!SpecializedTemplate.is() && "Already set to a variable template partial specialization!"); - SpecializedPartialSpecialization *PS = - new (getASTContext()) SpecializedPartialSpecialization(); + auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); PS->PartialSpecialization = PartialSpec; PS->TemplateArgs = TemplateArgs; SpecializedTemplate = PS; @@ -2815,15 +2812,14 @@ public: /// \c Outer::Inner, this function would return /// \c Outer::Inner. VarTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { - const VarTemplatePartialSpecializationDecl *First = + const auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getPointer(); } void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec) { - VarTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); First->InstantiatedFromMember.setPointer(PartialSpec); } @@ -2844,15 +2840,14 @@ public: /// U* X::Inner = (T*)(0) + 1; /// \endcode bool isMemberSpecialization() { - VarTemplatePartialSpecializationDecl *First = + const auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getInt(); } /// \brief Note that this member template is a specialization. void setMemberSpecialization() { - VarTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); assert(First->InstantiatedFromMember.getPointer() && "Only member templates can be member template specializations"); return First->InstantiatedFromMember.setInt(true); @@ -3021,11 +3016,11 @@ public: }; inline NamedDecl *getAsNamedDecl(TemplateParameter P) { - if (auto *PD = P.dyn_cast()) + if (auto *PD = P.dyn_cast()) return PD; - if (auto *PD = P.dyn_cast()) + if (auto *PD = P.dyn_cast()) return PD; - return P.get(); + return P.get(); } inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) { diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index f8a4dcc59a..b5bb13354a 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -667,8 +667,7 @@ class QualType { const ExtQualsTypeCommonBase *getCommonPtr() const { assert(!isNull() && "Cannot retrieve a NULL type pointer"); - uintptr_t CommonPtrVal - = reinterpret_cast(Value.getOpaqueValue()); + auto CommonPtrVal = reinterpret_cast(Value.getOpaqueValue()); CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); return reinterpret_cast(CommonPtrVal); } @@ -3544,7 +3543,7 @@ private: assert(hasExtParameterInfos()); // Find the end of the exception specification. - const char *ptr = reinterpret_cast(exception_begin()); + const auto *ptr = reinterpret_cast(exception_begin()); ptr += getExceptionSpecSize(); return reinterpret_cast(ptr); @@ -5499,8 +5498,8 @@ public: inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { QualType baseType = getBaseType(); - while (const ObjCObjectType *ObjT = baseType->getAs()) { - if (const ObjCInterfaceType *T = dyn_cast(ObjT)) + while (const auto *ObjT = baseType->getAs()) { + if (const auto *T = dyn_cast(ObjT)) return T->getDecl(); baseType = ObjT->getBaseType(); @@ -5922,10 +5921,10 @@ inline Qualifiers::GC QualType::getObjCGCAttr() const { } inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { - if (const PointerType *PT = t.getAs()) { - if (const FunctionType *FT = PT->getPointeeType()->getAs()) + if (const auto *PT = t.getAs()) { + if (const auto *FT = PT->getPointeeType()->getAs()) return FT->getExtInfo(); - } else if (const FunctionType *FT = t.getAs()) + } else if (const auto *FT = t.getAs()) return FT->getExtInfo(); return FunctionType::ExtInfo(); @@ -5970,7 +5969,7 @@ inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { /// analysis, the expression designates the object or function /// denoted by the reference, and the expression is an lvalue. inline QualType QualType::getNonReferenceType() const { - if (const ReferenceType *RefType = (*this)->getAs()) + if (const auto *RefType = (*this)->getAs()) return RefType->getPointeeType(); else return *this; @@ -6045,7 +6044,7 @@ inline bool Type::isRValueReferenceType() const { } inline bool Type::isFunctionPointerType() const { - if (const PointerType *T = getAs()) + if (const auto *T = getAs()) return T->getPointeeType()->isFunctionType(); else return false; @@ -6056,14 +6055,14 @@ inline bool Type::isMemberPointerType() const { } inline bool Type::isMemberFunctionPointerType() const { - if (const MemberPointerType* T = getAs()) + if (const auto *T = getAs()) return T->isMemberFunctionPointer(); else return false; } inline bool Type::isMemberDataPointerType() const { - if (const MemberPointerType* T = getAs()) + if (const auto *T = getAs()) return T->isMemberDataPointer(); else return false; @@ -6135,31 +6134,31 @@ inline bool Type::isAtomicType() const { } inline bool Type::isObjCQualifiedIdType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCQualifiedIdType(); return false; } inline bool Type::isObjCQualifiedClassType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCQualifiedClassType(); return false; } inline bool Type::isObjCIdType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCIdType(); return false; } inline bool Type::isObjCClassType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCClassType(); return false; } inline bool Type::isObjCSelType() const { - if (const PointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); return false; } @@ -6222,13 +6221,13 @@ inline bool Type::isSpecificBuiltinType(unsigned K) const { } inline bool Type::isPlaceholderType() const { - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) return BT->isPlaceholderType(); return false; } inline const BuiltinType *Type::getAsPlaceholderType() const { - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) if (BT->isPlaceholderType()) return BT; return nullptr; @@ -6236,38 +6235,38 @@ inline const BuiltinType *Type::getAsPlaceholderType() const { inline bool Type::isSpecificPlaceholderType(unsigned K) const { assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)); - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) return (BT->getKind() == (BuiltinType::Kind) K); return false; } inline bool Type::isNonOverloadPlaceholderType() const { - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) return BT->isNonOverloadPlaceholderType(); return false; } inline bool Type::isVoidType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Void; return false; } inline bool Type::isHalfType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Half; // FIXME: Should we allow complex __fp16? Probably not. return false; } inline bool Type::isFloat16Type() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Float16; return false; } inline bool Type::isNullPtrType() const { - if (const BuiltinType *BT = getAs()) + if (const auto *BT = getAs()) return BT->getKind() == BuiltinType::NullPtr; return false; } @@ -6276,7 +6275,7 @@ bool IsEnumDeclComplete(EnumDecl *); bool IsEnumDeclScoped(EnumDecl *); inline bool Type::isIntegerType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::Int128; if (const EnumType *ET = dyn_cast(CanonicalType)) { @@ -6289,7 +6288,7 @@ inline bool Type::isIntegerType() const { } inline bool Type::isScalarType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() > BuiltinType::Void && BT->getKind() <= BuiltinType::NullPtr; if (const EnumType *ET = dyn_cast(CanonicalType)) @@ -6304,20 +6303,20 @@ inline bool Type::isScalarType() const { } inline bool Type::isIntegralOrEnumerationType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::Int128; // Check for a complete enum type; incomplete enum types are not properly an // enumeration type in the sense required here. - if (const EnumType *ET = dyn_cast(CanonicalType)) + if (const auto *ET = dyn_cast(CanonicalType)) return IsEnumDeclComplete(ET->getDecl()); return false; } inline bool Type::isBooleanType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Bool; return false; } @@ -6394,7 +6393,7 @@ template const T *Type::getAs() const { "ArrayType cannot be used with getAs!"); // If this is directly a T type, return it. - if (const T *Ty = dyn_cast(this)) + if (const auto *Ty = dyn_cast(this)) return Ty; // If the canonical form of this type isn't the right kind, reject it. @@ -6410,7 +6409,7 @@ template const T *Type::getAsAdjusted() const { static_assert(!TypeIsArrayType::value, "ArrayType cannot be used with getAsAdjusted!"); // If this is directly a T type, return it. - if (const T *Ty = dyn_cast(this)) + if (const auto *Ty = dyn_cast(this)) return Ty; // If the canonical form of this type isn't the right kind, reject it. @@ -6440,7 +6439,7 @@ template const T *Type::getAsAdjusted() const { inline const ArrayType *Type::getAsArrayTypeUnsafe() const { // If this is directly an array type, return it. - if (const ArrayType *arr = dyn_cast(this)) + if (const auto *arr = dyn_cast(this)) return arr; // If the canonical form of this type isn't the right kind, reject it. @@ -6456,14 +6455,14 @@ template const T *Type::castAs() const { static_assert(!TypeIsArrayType::value, "ArrayType cannot be used with castAs!"); - if (const T *ty = dyn_cast(this)) return ty; + if (const auto *ty = dyn_cast(this)) return ty; assert(isa(CanonicalType)); return cast(getUnqualifiedDesugaredType()); } inline const ArrayType *Type::castAsArrayTypeUnsafe() const { assert(isa(CanonicalType)); - if (const ArrayType *arr = dyn_cast(this)) return arr; + if (const auto *arr = dyn_cast(this)) return arr; return cast(getUnqualifiedDesugaredType()); } diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index a7949b310c..8854f7879a 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -17,6 +17,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExternalASTSource.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" @@ -56,11 +57,11 @@ TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, begin()[Idx] = P; if (!P->isTemplateParameterPack()) { - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(P)) + if (const auto *NTTP = dyn_cast(P)) if (NTTP->getType()->containsUnexpandedParameterPack()) ContainsUnexpandedParameterPack = true; - if (TemplateTemplateParmDecl *TTP = dyn_cast(P)) + if (const auto *TTP = dyn_cast(P)) if (TTP->getTemplateParameters()->containsUnexpandedParameterPack()) ContainsUnexpandedParameterPack = true; @@ -118,11 +119,9 @@ unsigned TemplateParameterList::getDepth() const { return 0; const NamedDecl *FirstParm = getParam(0); - if (const TemplateTypeParmDecl *TTP - = dyn_cast(FirstParm)) + if (const auto *TTP = dyn_cast(FirstParm)) return TTP->getDepth(); - else if (const NonTypeTemplateParmDecl *NTTP - = dyn_cast(FirstParm)) + else if (const auto *NTTP = dyn_cast(FirstParm)) return NTTP->getDepth(); else return cast(FirstParm)->getDepth(); @@ -133,7 +132,7 @@ static void AdoptTemplateParameterList(TemplateParameterList *Params, for (NamedDecl *P : *Params) { P->setDeclContext(Owner); - if (auto *TTP = dyn_cast(P)) + if (const auto *TTP = dyn_cast(P)) AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner); } } @@ -258,7 +257,7 @@ FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C, RedeclarableTemplateDecl::CommonBase * FunctionTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.addDestruction(CommonPtr); return CommonPtr; } @@ -318,8 +317,8 @@ ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl); } - ConstrainedTemplateDeclInfo *const CTDI = new (C) ConstrainedTemplateDeclInfo; - ClassTemplateDecl *const New = + auto *const CTDI = new (C) ConstrainedTemplateDeclInfo; + auto *const New = new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl); New->setAssociatedConstraints(AssociatedConstraints); return New; @@ -349,7 +348,7 @@ ClassTemplateDecl::getPartialSpecializations() { RedeclarableTemplateDecl::CommonBase * ClassTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.addDestruction(CommonPtr); return CommonPtr; } @@ -453,8 +452,8 @@ TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack) { - TemplateTypeParmDecl *TTPDecl = - new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); + auto *TTPDecl = + new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); TTPDecl->setTypeForDecl(TTPType.getTypePtr()); return TTPDecl; @@ -709,7 +708,7 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, ClassTemplateDecl *SpecializedTemplate, ArrayRef Args, ClassTemplateSpecializationDecl *PrevDecl) { - ClassTemplateSpecializationDecl *Result = + auto *Result = new (Context, DC) ClassTemplateSpecializationDecl( Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc, SpecializedTemplate, Args, PrevDecl); @@ -722,7 +721,7 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, ClassTemplateSpecializationDecl * ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - ClassTemplateSpecializationDecl *Result = + auto *Result = new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization); Result->MayHaveOutOfDateDef = false; return Result; @@ -732,7 +731,7 @@ void ClassTemplateSpecializationDecl::getNameForDiagnostic( raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); - auto *PS = dyn_cast(this); + const auto *PS = dyn_cast(this); if (const ASTTemplateArgumentListInfo *ArgsAsWritten = PS ? PS->getTemplateArgsAsWritten() : nullptr) { printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy); @@ -744,8 +743,8 @@ void ClassTemplateSpecializationDecl::getNameForDiagnostic( ClassTemplateDecl * ClassTemplateSpecializationDecl::getSpecializedTemplate() const { - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) + if (const auto *PartialSpec = + SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization->getSpecializedTemplate(); return SpecializedTemplate.get(); } @@ -770,7 +769,7 @@ ClassTemplateSpecializationDecl::getSourceRange() const { // uses ExplicitInfo to record the TypeAsWritten, but the source // locations should be retrieved from the instantiation pattern. using CTPSDecl = ClassTemplatePartialSpecializationDecl; - CTPSDecl *ctpsd = const_cast(cast(this)); + auto *ctpsd = const_cast(cast(this)); CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember(); assert(inst_from != nullptr); return inst_from->getSourceRange(); @@ -782,9 +781,9 @@ ClassTemplateSpecializationDecl::getSourceRange() const { inst_from = getInstantiatedFrom(); if (inst_from.isNull()) return getSpecializedTemplate()->getSourceRange(); - if (ClassTemplateDecl *ctd = inst_from.dyn_cast()) + if (const auto *ctd = inst_from.dyn_cast()) return ctd->getSourceRange(); - return inst_from.get() + return inst_from.get() ->getSourceRange(); } } @@ -826,7 +825,7 @@ Create(ASTContext &Context, TagKind TK,DeclContext *DC, const ASTTemplateArgumentListInfo *ASTArgInfos = ASTTemplateArgumentListInfo::Create(Context, ArgInfos); - ClassTemplatePartialSpecializationDecl *Result = new (Context, DC) + auto *Result = new (Context, DC) ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc, Params, SpecializedTemplate, Args, ASTArgInfos, PrevDecl); @@ -840,8 +839,7 @@ Create(ASTContext &Context, TagKind TK,DeclContext *DC, ClassTemplatePartialSpecializationDecl * ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - ClassTemplatePartialSpecializationDecl *Result = - new (C, ID) ClassTemplatePartialSpecializationDecl(C); + auto *Result = new (C, ID) ClassTemplatePartialSpecializationDecl(C); Result->MayHaveOutOfDateDef = false; return Result; } @@ -887,7 +885,7 @@ TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, RedeclarableTemplateDecl::CommonBase * TypeAliasTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.addDestruction(CommonPtr); return CommonPtr; } @@ -950,7 +948,7 @@ VarTemplateDecl::getPartialSpecializations() { RedeclarableTemplateDecl::CommonBase * VarTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.addDestruction(CommonPtr); return CommonPtr; } @@ -1048,7 +1046,7 @@ void VarTemplateSpecializationDecl::getNameForDiagnostic( raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); - auto *PS = dyn_cast(this); + const auto *PS = dyn_cast(this); if (const ASTTemplateArgumentListInfo *ArgsAsWritten = PS ? PS->getTemplateArgsAsWritten() : nullptr) { printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy); @@ -1059,7 +1057,7 @@ void VarTemplateSpecializationDecl::getNameForDiagnostic( } VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { - if (SpecializedPartialSpecialization *PartialSpec = + if (const auto *PartialSpec = SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization->getSpecializedTemplate(); return SpecializedTemplate.get(); @@ -1104,7 +1102,7 @@ VarTemplatePartialSpecializationDecl::Create( const ASTTemplateArgumentListInfo *ASTArgInfos = ASTTemplateArgumentListInfo::Create(Context, ArgInfos); - VarTemplatePartialSpecializationDecl *Result = + auto *Result = new (Context, DC) VarTemplatePartialSpecializationDecl( Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, S, Args, ASTArgInfos); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 021699f3be..c2733f2563 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -29,6 +29,7 @@ #include "clang/AST/TypeVisitor.h" #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/ExceptionSpecificationType.h" +#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" @@ -228,7 +229,7 @@ VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, /// This method should never be used when type qualifiers are meaningful. const Type *Type::getArrayElementTypeNoTypeQual() const { // If this is directly an array type, return it. - if (const ArrayType *ATy = dyn_cast(this)) + if (const auto *ATy = dyn_cast(this)) return ATy->getElementType().getTypePtr(); // If the canonical form of this type isn't the right kind, reject it. @@ -264,7 +265,7 @@ QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { #define ABSTRACT_TYPE(Class, Parent) #define TYPE(Class, Parent) \ case Type::Class: { \ - const Class##Type *ty = cast(this); \ + const auto *ty = cast(this); \ if (!ty->isSugared()) return QualType(ty, 0); \ return ty->desugar(); \ } @@ -283,7 +284,7 @@ SplitQualType QualType::getSplitDesugaredType(QualType T) { #define ABSTRACT_TYPE(Class, Parent) #define TYPE(Class, Parent) \ case Type::Class: { \ - const Class##Type *Ty = cast(CurTy); \ + const auto *Ty = cast(CurTy); \ if (!Ty->isSugared()) \ return SplitQualType(Ty, Qs); \ Cur = Ty->desugar(); \ @@ -312,7 +313,7 @@ SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { #define ABSTRACT_TYPE(Class, Parent) #define TYPE(Class, Parent) \ case Type::Class: { \ - const Class##Type *ty = cast(split.Ty); \ + const auto *ty = cast(split.Ty); \ if (!ty->isSugared()) goto done; \ next = ty->desugar(); \ break; \ @@ -335,7 +336,7 @@ SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { QualType QualType::IgnoreParens(QualType T) { // FIXME: this seems inherently un-qualifiers-safe. - while (const ParenType *PT = T->getAs()) + while (const auto *PT = T->getAs()) T = PT->getInnerType(); return T; } @@ -345,13 +346,13 @@ QualType QualType::IgnoreParens(QualType T) { /// reaches a T or a non-sugared type. template static const T *getAsSugar(const Type *Cur) { while (true) { - if (const T *Sugar = dyn_cast(Cur)) + if (const auto *Sugar = dyn_cast(Cur)) return Sugar; switch (Cur->getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) #define TYPE(Class, Parent) \ case Type::Class: { \ - const Class##Type *Ty = cast(Cur); \ + const auto *Ty = cast(Cur); \ if (!Ty->isSugared()) return 0; \ Cur = Ty->desugar().getTypePtr(); \ break; \ @@ -384,7 +385,7 @@ const Type *Type::getUnqualifiedDesugaredType() const { #define ABSTRACT_TYPE(Class, Parent) #define TYPE(Class, Parent) \ case Class: { \ - const Class##Type *Ty = cast(Cur); \ + const auto *Ty = cast(Cur); \ if (!Ty->isSugared()) return Cur; \ Cur = Ty->desugar().getTypePtr(); \ break; \ @@ -395,28 +396,31 @@ const Type *Type::getUnqualifiedDesugaredType() const { } bool Type::isClassType() const { - if (const RecordType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getDecl()->isClass(); return false; } bool Type::isStructureType() const { - if (const RecordType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getDecl()->isStruct(); return false; } + bool Type::isObjCBoxableRecordType() const { - if (const RecordType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getDecl()->hasAttr(); return false; } + bool Type::isInterfaceType() const { - if (const RecordType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getDecl()->isInterface(); return false; } + bool Type::isStructureOrClassType() const { - if (const RecordType *RT = getAs()) { + if (const auto *RT = getAs()) { RecordDecl *RD = RT->getDecl(); return RD->isStruct() || RD->isClass() || RD->isInterface(); } @@ -424,19 +428,19 @@ bool Type::isStructureOrClassType() const { } bool Type::isVoidPointerType() const { - if (const PointerType *PT = getAs()) + if (const auto *PT = getAs()) return PT->getPointeeType()->isVoidType(); return false; } bool Type::isUnionType() const { - if (const RecordType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getDecl()->isUnion(); return false; } bool Type::isComplexType() const { - if (const ComplexType *CT = dyn_cast(CanonicalType)) + if (const auto *CT = dyn_cast(CanonicalType)) return CT->getElementType()->isFloatingType(); return false; } @@ -447,37 +451,37 @@ bool Type::isComplexIntegerType() const { } const ComplexType *Type::getAsComplexIntegerType() const { - if (const ComplexType *Complex = getAs()) + if (const auto *Complex = getAs()) if (Complex->getElementType()->isIntegerType()) return Complex; return nullptr; } QualType Type::getPointeeType() const { - if (const PointerType *PT = getAs()) + if (const auto *PT = getAs()) return PT->getPointeeType(); - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->getPointeeType(); - if (const BlockPointerType *BPT = getAs()) + if (const auto *BPT = getAs()) return BPT->getPointeeType(); - if (const ReferenceType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getPointeeType(); - if (const MemberPointerType *MPT = getAs()) + if (const auto *MPT = getAs()) return MPT->getPointeeType(); - if (const DecayedType *DT = getAs()) + if (const auto *DT = getAs()) return DT->getPointeeType(); - return QualType(); + return {}; } const RecordType *Type::getAsStructureType() const { // If this is directly a structure type, return it. - if (const RecordType *RT = dyn_cast(this)) { + if (const auto *RT = dyn_cast(this)) { if (RT->getDecl()->isStruct()) return RT; } // If the canonical form of this type isn't the right kind, reject it. - if (const RecordType *RT = dyn_cast(CanonicalType)) { + if (const auto *RT = dyn_cast(CanonicalType)) { if (!RT->getDecl()->isStruct()) return nullptr; @@ -490,13 +494,13 @@ const RecordType *Type::getAsStructureType() const { const RecordType *Type::getAsUnionType() const { // If this is directly a union type, return it. - if (const RecordType *RT = dyn_cast(this)) { + if (const auto *RT = dyn_cast(this)) { if (RT->getDecl()->isUnion()) return RT; } // If the canonical form of this type isn't the right kind, reject it. - if (const RecordType *RT = dyn_cast(CanonicalType)) { + if (const auto *RT = dyn_cast(CanonicalType)) { if (!RT->getDecl()->isUnion()) return nullptr; @@ -512,7 +516,7 @@ bool Type::isObjCIdOrObjectKindOfType(const ASTContext &ctx, const ObjCObjectType *&bound) const { bound = nullptr; - const ObjCObjectPointerType *OPT = getAs(); + const auto *OPT = getAs(); if (!OPT) return false; @@ -535,7 +539,7 @@ bool Type::isObjCIdOrObjectKindOfType(const ASTContext &ctx, } bool Type::isObjCClassOrClassKindOfType() const { - const ObjCObjectPointerType *OPT = getAs(); + const auto *OPT = getAs(); if (!OPT) return false; @@ -560,7 +564,7 @@ bool Type::isObjCClassOrClassKindOfType() const { bool Type::isObjCInertUnsafeUnretainedType() const { const Type *cur = this; while (true) { - if (auto attributed = dyn_cast(cur)) { + if (const auto attributed = dyn_cast(cur)) { if (attributed->getAttrKind() == AttributedType::attr_objc_inert_unsafe_unretained) return true; @@ -622,7 +626,7 @@ bool ObjCObjectType::isSpecialized() const { return true; // Otherwise, check whether the base type is specialized. - if (auto objcObject = getBaseType()->getAs()) { + if (const auto objcObject = getBaseType()->getAs()) { // Terminate when we reach an interface type. if (isa(objcObject)) return false; @@ -640,7 +644,7 @@ ArrayRef ObjCObjectType::getTypeArgs() const { return getTypeArgsAsWritten(); // Look at the base type, which might have type arguments. - if (auto objcObject = getBaseType()->getAs()) { + if (const auto objcObject = getBaseType()->getAs()) { // Terminate when we reach an interface type. if (isa(objcObject)) return {}; @@ -657,7 +661,7 @@ bool ObjCObjectType::isKindOfType() const { return true; // Look at the base type, which might have type arguments. - if (auto objcObject = getBaseType()->getAs()) { + if (const auto objcObject = getBaseType()->getAs()) { // Terminate when we reach an interface type. if (isa(objcObject)) return false; @@ -677,10 +681,8 @@ QualType ObjCObjectType::stripObjCKindOfTypeAndQuals( // Recursively strip __kindof. SplitQualType splitBaseType = getBaseType().split(); QualType baseType(splitBaseType.Ty, 0); - if (const ObjCObjectType *baseObj - = splitBaseType.Ty->getAs()) { + if (const auto *baseObj = splitBaseType.Ty->getAs()) baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx); - } return ctx.getObjCObjectType(ctx.getQualifiedType(baseType, splitBaseType.Quals), @@ -733,7 +735,7 @@ public: QualType VisitComplexType(const ComplexType *T) { QualType elementType = recurse(T->getElementType()); if (elementType.isNull()) - return QualType(); + return {}; if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) return QualType(T, 0); @@ -744,7 +746,7 @@ public: QualType VisitPointerType(const PointerType *T) { QualType pointeeType = recurse(T->getPointeeType()); if (pointeeType.isNull()) - return QualType(); + return {}; if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) return QualType(T, 0); @@ -755,7 +757,7 @@ public: QualType VisitBlockPointerType(const BlockPointerType *T) { QualType pointeeType = recurse(T->getPointeeType()); if (pointeeType.isNull()) - return QualType(); + return {}; if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) return QualType(T, 0); @@ -766,7 +768,7 @@ public: QualType VisitLValueReferenceType(const LValueReferenceType *T) { QualType pointeeType = recurse(T->getPointeeTypeAsWritten()); if (pointeeType.isNull()) - return QualType(); + return {}; if (pointeeType.getAsOpaquePtr() == T->getPointeeTypeAsWritten().getAsOpaquePtr()) @@ -778,7 +780,7 @@ public: QualType VisitRValueReferenceType(const RValueReferenceType *T) { QualType pointeeType = recurse(T->getPointeeTypeAsWritten()); if (pointeeType.isNull()) - return QualType(); + return {}; if (pointeeType.getAsOpaquePtr() == T->getPointeeTypeAsWritten().getAsOpaquePtr()) @@ -790,7 +792,7 @@ public: QualType VisitMemberPointerType(const MemberPointerType *T) { QualType pointeeType = recurse(T->getPointeeType()); if (pointeeType.isNull()) - return QualType(); + return {}; if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) return QualType(T, 0); @@ -801,7 +803,7 @@ public: QualType VisitConstantArrayType(const ConstantArrayType *T) { QualType elementType = recurse(T->getElementType()); if (elementType.isNull()) - return QualType(); + return {}; if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) return QualType(T, 0); @@ -814,7 +816,7 @@ public: QualType VisitVariableArrayType(const VariableArrayType *T) { QualType elementType = recurse(T->getElementType()); if (elementType.isNull()) - return QualType(); + return {}; if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) return QualType(T, 0); @@ -828,7 +830,7 @@ public: QualType VisitIncompleteArrayType(const IncompleteArrayType *T) { QualType elementType = recurse(T->getElementType()); if (elementType.isNull()) - return QualType(); + return {}; if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) return QualType(T, 0); @@ -840,7 +842,7 @@ public: QualType VisitVectorType(const VectorType *T) { QualType elementType = recurse(T->getElementType()); if (elementType.isNull()) - return QualType(); + return {}; if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) return QualType(T, 0); @@ -852,7 +854,7 @@ public: QualType VisitExtVectorType(const ExtVectorType *T) { QualType elementType = recurse(T->getElementType()); if (elementType.isNull()) - return QualType(); + return {}; if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) return QualType(T, 0); @@ -863,7 +865,7 @@ public: QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T) { QualType returnType = recurse(T->getReturnType()); if (returnType.isNull()) - return QualType(); + return {}; if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr()) return QualType(T, 0); @@ -874,7 +876,7 @@ public: QualType VisitFunctionProtoType(const FunctionProtoType *T) { QualType returnType = recurse(T->getReturnType()); if (returnType.isNull()) - return QualType(); + return {}; // Transform parameter types. SmallVector paramTypes; @@ -882,7 +884,7 @@ public: for (auto paramType : T->getParamTypes()) { QualType newParamType = recurse(paramType); if (newParamType.isNull()) - return QualType(); + return {}; if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr()) paramChanged = true; @@ -898,10 +900,9 @@ public: for (auto exceptionType : info.ExceptionSpec.Exceptions) { QualType newExceptionType = recurse(exceptionType); if (newExceptionType.isNull()) - return QualType(); + return {}; - if (newExceptionType.getAsOpaquePtr() - != exceptionType.getAsOpaquePtr()) + if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr()) exceptionChanged = true; exceptionTypes.push_back(newExceptionType); @@ -923,7 +924,7 @@ public: QualType VisitParenType(const ParenType *T) { QualType innerType = recurse(T->getInnerType()); if (innerType.isNull()) - return QualType(); + return {}; if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr()) return QualType(T, 0); @@ -937,11 +938,11 @@ public: QualType VisitAdjustedType(const AdjustedType *T) { QualType originalType = recurse(T->getOriginalType()); if (originalType.isNull()) - return QualType(); + return {}; QualType adjustedType = recurse(T->getAdjustedType()); if (adjustedType.isNull()) - return QualType(); + return {}; if (originalType.getAsOpaquePtr() == T->getOriginalType().getAsOpaquePtr() && @@ -954,7 +955,7 @@ public: QualType VisitDecayedType(const DecayedType *T) { QualType originalType = recurse(T->getOriginalType()); if (originalType.isNull()) - return QualType(); + return {}; if (originalType.getAsOpaquePtr() == T->getOriginalType().getAsOpaquePtr()) @@ -976,11 +977,11 @@ public: QualType VisitAttributedType(const AttributedType *T) { QualType modifiedType = recurse(T->getModifiedType()); if (modifiedType.isNull()) - return QualType(); + return {}; QualType equivalentType = recurse(T->getEquivalentType()); if (equivalentType.isNull()) - return QualType(); + return {}; if (modifiedType.getAsOpaquePtr() == T->getModifiedType().getAsOpaquePtr() && @@ -995,7 +996,7 @@ public: QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { QualType replacementType = recurse(T->getReplacementType()); if (replacementType.isNull()) - return QualType(); + return {}; if (replacementType.getAsOpaquePtr() == T->getReplacementType().getAsOpaquePtr()) @@ -1014,7 +1015,7 @@ public: QualType deducedType = recurse(T->getDeducedType()); if (deducedType.isNull()) - return QualType(); + return {}; if (deducedType.getAsOpaquePtr() == T->getDeducedType().getAsOpaquePtr()) @@ -1030,7 +1031,7 @@ public: QualType VisitObjCObjectType(const ObjCObjectType *T) { QualType baseType = recurse(T->getBaseType()); if (baseType.isNull()) - return QualType(); + return {}; // Transform type arguments. bool typeArgChanged = false; @@ -1038,7 +1039,7 @@ public: for (auto typeArg : T->getTypeArgsAsWritten()) { QualType newTypeArg = recurse(typeArg); if (newTypeArg.isNull()) - return QualType(); + return {}; if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) typeArgChanged = true; @@ -1061,7 +1062,7 @@ public: QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { QualType pointeeType = recurse(T->getPointeeType()); if (pointeeType.isNull()) - return QualType(); + return {}; if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) @@ -1073,7 +1074,7 @@ public: QualType VisitAtomicType(const AtomicType *T) { QualType valueType = recurse(T->getValueType()); if (valueType.isNull()) - return QualType(); + return {}; if (valueType.getAsOpaquePtr() == T->getValueType().getAsOpaquePtr()) @@ -1184,7 +1185,7 @@ QualType QualType::substObjCTypeArgs( typeArgs, ObjCSubstitutionContext::Result); if (returnType.isNull()) - return QualType(); + return {}; // Handle non-prototyped functions, which only substitute into the result // type. @@ -1209,7 +1210,7 @@ QualType QualType::substObjCTypeArgs( typeArgs, ObjCSubstitutionContext::Parameter); if (newParamType.isNull()) - return QualType(); + return {}; if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr()) paramChanged = true; @@ -1228,7 +1229,7 @@ QualType QualType::substObjCTypeArgs( typeArgs, ObjCSubstitutionContext::Ordinary); if (newExceptionType.isNull()) - return QualType(); + return {}; if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr()) @@ -1262,7 +1263,7 @@ QualType QualType::substObjCTypeArgs( ctx, typeArgs, ObjCSubstitutionContext::Ordinary); if (newTypeArg.isNull()) - return QualType(); + return {}; if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) { // If we're substituting based on an unspecialized context type, @@ -1335,7 +1336,7 @@ QualType QualType::stripObjCKindOfType(const ASTContext &constCtx) const { } QualType QualType::getAtomicUnqualifiedType() const { - if (auto AT = getTypePtr()->getAs()) + if (const auto AT = getTypePtr()->getAs()) return AT->getValueType().getUnqualifiedType(); return getUnqualifiedType(); } @@ -1343,12 +1344,12 @@ QualType QualType::getAtomicUnqualifiedType() const { Optional> Type::getObjCSubstitutions( const DeclContext *dc) const { // Look through method scopes. - if (auto method = dyn_cast(dc)) + if (const auto method = dyn_cast(dc)) dc = method->getDeclContext(); // Find the class or category in which the type we're substituting // was declared. - const ObjCInterfaceDecl *dcClassDecl = dyn_cast(dc); + const auto *dcClassDecl = dyn_cast(dc); const ObjCCategoryDecl *dcCategoryDecl = nullptr; ObjCTypeParamList *dcTypeParams = nullptr; if (dcClassDecl) { @@ -1525,7 +1526,7 @@ const ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { // There is no sugar for ObjCObjectType's, just return the canonical // type pointer if it is the right class. There is no typedef information to // return and these cannot be Address-space qualified. - if (const ObjCObjectType *T = getAs()) + if (const auto *T = getAs()) if (T->getNumProtocols() && T->getInterface()) return T; return nullptr; @@ -1538,7 +1539,7 @@ bool Type::isObjCQualifiedInterfaceType() const { const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { // There is no sugar for ObjCQualifiedIdType's, just return the canonical // type pointer if it is the right class. - if (const ObjCObjectPointerType *OPT = getAs()) { + if (const auto *OPT = getAs()) { if (OPT->isObjCQualifiedIdType()) return OPT; } @@ -1548,7 +1549,7 @@ const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { const ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { // There is no sugar for ObjCQualifiedClassType's, just return the canonical // type pointer if it is the right class. - if (const ObjCObjectPointerType *OPT = getAs()) { + if (const auto *OPT = getAs()) { if (OPT->isObjCQualifiedClassType()) return OPT; } @@ -1556,7 +1557,7 @@ const ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { } const ObjCObjectType *Type::getAsObjCInterfaceType() const { - if (const ObjCObjectType *OT = getAs()) { + if (const auto *OT = getAs()) { if (OT->getInterface()) return OT; } @@ -1564,7 +1565,7 @@ const ObjCObjectType *Type::getAsObjCInterfaceType() const { } const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { - if (const ObjCObjectPointerType *OPT = getAs()) { + if (const auto *OPT = getAs()) { if (OPT->getInterfaceType()) return OPT; } @@ -1573,14 +1574,14 @@ const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { const CXXRecordDecl *Type::getPointeeCXXRecordDecl() const { QualType PointeeType; - if (const PointerType *PT = getAs()) + if (const auto *PT = getAs()) PointeeType = PT->getPointeeType(); - else if (const ReferenceType *RT = getAs()) + else if (const auto *RT = getAs()) PointeeType = RT->getPointeeType(); else return nullptr; - if (const RecordType *RT = PointeeType->getAs()) + if (const auto *RT = PointeeType->getAs()) return dyn_cast(RT->getDecl()); return nullptr; @@ -1693,7 +1694,7 @@ bool Type::hasAutoForTrailingReturnType() const { } bool Type::hasIntegerRepresentation() const { - if (const VectorType *VT = dyn_cast(CanonicalType)) + if (const auto *VT = dyn_cast(CanonicalType)) return VT->getElementType()->isIntegerType(); else return isIntegerType(); @@ -1719,20 +1720,20 @@ bool Type::hasIntegerRepresentation() const { /// /// \returns true if the type is considered an integral type, false otherwise. bool Type::isIntegralType(const ASTContext &Ctx) const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::Int128; // Complete enum types are integral in C. if (!Ctx.getLangOpts().CPlusPlus) - if (const EnumType *ET = dyn_cast(CanonicalType)) + if (const auto *ET = dyn_cast(CanonicalType)) return ET->getDecl()->isComplete(); return false; } bool Type::isIntegralOrUnscopedEnumerationType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::Int128; @@ -1740,14 +1741,14 @@ bool Type::isIntegralOrUnscopedEnumerationType() const { // enumeration type in the sense required here. // C++0x: However, if the underlying type of the enum is fixed, it is // considered complete. - if (const EnumType *ET = dyn_cast(CanonicalType)) + if (const auto *ET = dyn_cast(CanonicalType)) return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); return false; } bool Type::isCharType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Char_U || BT->getKind() == BuiltinType::UChar || BT->getKind() == BuiltinType::Char_S || @@ -1756,20 +1757,20 @@ bool Type::isCharType() const { } bool Type::isWideCharType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::WChar_S || BT->getKind() == BuiltinType::WChar_U; return false; } bool Type::isChar16Type() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Char16; return false; } bool Type::isChar32Type() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() == BuiltinType::Char32; return false; } @@ -1777,7 +1778,7 @@ bool Type::isChar32Type() const { /// \brief Determine whether this type is any of the built-in character /// types. bool Type::isAnyCharacterType() const { - const BuiltinType *BT = dyn_cast(CanonicalType); + const auto *BT = dyn_cast(CanonicalType); if (!BT) return false; switch (BT->getKind()) { default: return false; @@ -1797,7 +1798,7 @@ bool Type::isAnyCharacterType() const { /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], /// an enum decl which has a signed representation bool Type::isSignedIntegerType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) { + if (const auto *BT = dyn_cast(CanonicalType)) { return BT->getKind() >= BuiltinType::Char_S && BT->getKind() <= BuiltinType::Int128; } @@ -1813,12 +1814,12 @@ bool Type::isSignedIntegerType() const { } bool Type::isSignedIntegerOrEnumerationType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) { + if (const auto *BT = dyn_cast(CanonicalType)) { return BT->getKind() >= BuiltinType::Char_S && BT->getKind() <= BuiltinType::Int128; } - if (const EnumType *ET = dyn_cast(CanonicalType)) { + if (const auto *ET = dyn_cast(CanonicalType)) { if (ET->getDecl()->isComplete()) return ET->getDecl()->getIntegerType()->isSignedIntegerType(); } @@ -1827,7 +1828,7 @@ bool Type::isSignedIntegerOrEnumerationType() const { } bool Type::hasSignedIntegerRepresentation() const { - if (const VectorType *VT = dyn_cast(CanonicalType)) + if (const auto *VT = dyn_cast(CanonicalType)) return VT->getElementType()->isSignedIntegerOrEnumerationType(); else return isSignedIntegerOrEnumerationType(); @@ -1837,12 +1838,12 @@ bool Type::hasSignedIntegerRepresentation() const { /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum /// decl which has an unsigned representation bool Type::isUnsignedIntegerType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) { + if (const auto *BT = dyn_cast(CanonicalType)) { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::UInt128; } - if (const EnumType *ET = dyn_cast(CanonicalType)) { + if (const auto *ET = dyn_cast(CanonicalType)) { // Incomplete enum types are not treated as integer types. // FIXME: In C++, enum types are never integer types. if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) @@ -1853,12 +1854,12 @@ bool Type::isUnsignedIntegerType() const { } bool Type::isUnsignedIntegerOrEnumerationType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) { + if (const auto *BT = dyn_cast(CanonicalType)) { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::UInt128; } - if (const EnumType *ET = dyn_cast(CanonicalType)) { + if (const auto *ET = dyn_cast(CanonicalType)) { if (ET->getDecl()->isComplete()) return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); } @@ -1867,48 +1868,48 @@ bool Type::isUnsignedIntegerOrEnumerationType() const { } bool Type::hasUnsignedIntegerRepresentation() const { - if (const VectorType *VT = dyn_cast(CanonicalType)) + if (const auto *VT = dyn_cast(CanonicalType)) return VT->getElementType()->isUnsignedIntegerOrEnumerationType(); else return isUnsignedIntegerOrEnumerationType(); } bool Type::isFloatingType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Half && BT->getKind() <= BuiltinType::Float128; - if (const ComplexType *CT = dyn_cast(CanonicalType)) + if (const auto *CT = dyn_cast(CanonicalType)) return CT->getElementType()->isFloatingType(); return false; } bool Type::hasFloatingRepresentation() const { - if (const VectorType *VT = dyn_cast(CanonicalType)) + if (const auto *VT = dyn_cast(CanonicalType)) return VT->getElementType()->isFloatingType(); else return isFloatingType(); } bool Type::isRealFloatingType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->isFloatingPoint(); return false; } bool Type::isRealType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::Float128; - if (const EnumType *ET = dyn_cast(CanonicalType)) + if (const auto *ET = dyn_cast(CanonicalType)) return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); return false; } bool Type::isArithmeticType() const { - if (const BuiltinType *BT = dyn_cast(CanonicalType)) + if (const auto *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::Float128; - if (const EnumType *ET = dyn_cast(CanonicalType)) + if (const auto *ET = dyn_cast(CanonicalType)) // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). // If a body isn't seen by the time we get here, return false. // @@ -1923,7 +1924,7 @@ Type::ScalarTypeKind Type::getScalarTypeKind() const { assert(isScalarType()); const Type *T = CanonicalType.getTypePtr(); - if (const BuiltinType *BT = dyn_cast(T)) { + if (const auto *BT = dyn_cast(T)) { if (BT->getKind() == BuiltinType::Bool) return STK_Bool; if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer; if (BT->isInteger()) return STK_Integral; @@ -1940,7 +1941,7 @@ Type::ScalarTypeKind Type::getScalarTypeKind() const { } else if (isa(T)) { assert(cast(T)->getDecl()->isComplete()); return STK_Integral; - } else if (const ComplexType *CT = dyn_cast(T)) { + } else if (const auto *CT = dyn_cast(T)) { if (CT->getElementType()->isRealFloatingType()) return STK_FloatingComplex; return STK_IntegralComplex; @@ -1959,8 +1960,8 @@ Type::ScalarTypeKind Type::getScalarTypeKind() const { /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also /// includes union types. bool Type::isAggregateType() const { - if (const RecordType *Record = dyn_cast(CanonicalType)) { - if (CXXRecordDecl *ClassDecl = dyn_cast(Record->getDecl())) + if (const auto *Record = dyn_cast(CanonicalType)) { + if (const auto *ClassDecl = dyn_cast(Record->getDecl())) return ClassDecl->isAggregate(); return true; @@ -2099,8 +2100,8 @@ bool QualType::isCXX98PODType(const ASTContext &Context) const { return true; case Type::Record: - if (CXXRecordDecl *ClassDecl - = dyn_cast(cast(CanonicalType)->getDecl())) + if (const auto *ClassDecl = + dyn_cast(cast(CanonicalType)->getDecl())) return ClassDecl->isPOD(); // C struct/union is POD. @@ -2138,9 +2139,8 @@ bool QualType::isTrivialType(const ASTContext &Context) const { // As an extension, Clang treats vector types as Scalar types. if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) return true; - if (const RecordType *RT = CanonicalType->getAs()) { - if (const CXXRecordDecl *ClassDecl = - dyn_cast(RT->getDecl())) { + if (const auto *RT = CanonicalType->getAs()) { + if (const auto *ClassDecl = dyn_cast(RT->getDecl())) { // C++11 [class]p6: // A trivial class is a class that has a default constructor, // has no non-trivial default constructors, and is trivially @@ -2182,9 +2182,8 @@ bool QualType::isTriviallyCopyableType(const ASTContext &Context) const { if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) return true; - if (const RecordType *RT = CanonicalType->getAs()) { - if (const CXXRecordDecl *ClassDecl = - dyn_cast(RT->getDecl())) { + if (const auto *RT = CanonicalType->getAs()) { + if (const auto *ClassDecl = dyn_cast(RT->getDecl())) { if (!ClassDecl->isTriviallyCopyable()) return false; } @@ -2287,7 +2286,7 @@ bool Type::isLiteralType(const ASTContext &Ctx) const { if (BaseTy->isReferenceType()) return true; // -- a class type that has all of the following properties: - if (const RecordType *RT = BaseTy->getAs()) { + if (const auto *RT = BaseTy->getAs()) { // -- a trivial destructor, // -- every constructor call and full-expression in the // brace-or-equal-initializers for non-static data members (if any) @@ -2298,15 +2297,14 @@ bool Type::isLiteralType(const ASTContext &Ctx) const { // -- all non-static data members and base classes of literal types // // We resolve DR1361 by ignoring the second bullet. - if (const CXXRecordDecl *ClassDecl = - dyn_cast(RT->getDecl())) + if (const auto *ClassDecl = dyn_cast(RT->getDecl())) return ClassDecl->isLiteral(); return true; } // We treat _Atomic T as a literal type if T is a literal type. - if (const AtomicType *AT = BaseTy->getAs()) + if (const auto *AT = BaseTy->getAs()) return AT->getValueType()->isLiteralType(Ctx); // If this type hasn't been deduced yet, then conservatively assume that @@ -2335,9 +2333,8 @@ bool Type::isStandardLayoutType() const { // As an extension, Clang treats vector types as Scalar types. if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; - if (const RecordType *RT = BaseTy->getAs()) { - if (const CXXRecordDecl *ClassDecl = - dyn_cast(RT->getDecl())) + if (const auto *RT = BaseTy->getAs()) { + if (const auto *ClassDecl = dyn_cast(RT->getDecl())) if (!ClassDecl->isStandardLayout()) return false; @@ -2375,9 +2372,8 @@ bool QualType::isCXX11PODType(const ASTContext &Context) const { // As an extension, Clang treats vector types as Scalar types. if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; - if (const RecordType *RT = BaseTy->getAs()) { - if (const CXXRecordDecl *ClassDecl = - dyn_cast(RT->getDecl())) { + if (const auto *RT = BaseTy->getAs()) { + if (const auto *ClassDecl = dyn_cast(RT->getDecl())) { // C++11 [class]p10: // A POD struct is a non-union class that is both a trivial class [...] if (!ClassDecl->isTrivial()) return false; @@ -2405,8 +2401,8 @@ bool QualType::isCXX11PODType(const ASTContext &Context) const { } bool Type::isAlignValT() const { - if (auto *ET = getAs()) { - auto *II = ET->getDecl()->getIdentifier(); + if (const auto *ET = getAs()) { + IdentifierInfo *II = ET->getDecl()->getIdentifier(); if (II && II->isStr("align_val_t") && ET->getDecl()->isInStdNamespace()) return true; } @@ -2414,8 +2410,8 @@ bool Type::isAlignValT() const { } bool Type::isStdByteType() const { - if (auto *ET = getAs()) { - auto *II = ET->getDecl()->getIdentifier(); + if (const auto *ET = getAs()) { + IdentifierInfo *II = ET->getDecl()->getIdentifier(); if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace()) return true; } @@ -2423,7 +2419,7 @@ bool Type::isStdByteType() const { } bool Type::isPromotableIntegerType() const { - if (const BuiltinType *BT = getAs()) + if (const auto *BT = getAs()) switch (BT->getKind()) { case BuiltinType::Bool: case BuiltinType::Char_S: @@ -2443,7 +2439,7 @@ bool Type::isPromotableIntegerType() const { // Enumerated types are promotable to their compatible integer types // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). - if (const EnumType *ET = getAs()){ + if (const auto *ET = getAs()){ if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() || ET->getDecl()->isScoped()) return false; @@ -2550,7 +2546,7 @@ TypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { StringRef TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { switch (Keyword) { - case ETK_None: return ""; + case ETK_None: return {}; case ETK_Typename: return "typename"; case ETK_Class: return "class"; case ETK_Struct: return "struct"; @@ -2598,12 +2594,12 @@ DependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, bool Type::isElaboratedTypeSpecifier() const { ElaboratedTypeKeyword Keyword; - if (const ElaboratedType *Elab = dyn_cast(this)) + if (const auto *Elab = dyn_cast(this)) Keyword = Elab->getKeyword(); - else if (const DependentNameType *DepName = dyn_cast(this)) + else if (const auto *DepName = dyn_cast(this)) Keyword = DepName->getKeyword(); - else if (const DependentTemplateSpecializationType *DepTST = - dyn_cast(this)) + else if (const auto *DepTST = + dyn_cast(this)) Keyword = DepTST->getKeyword(); else return false; @@ -2718,7 +2714,7 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const { } QualType QualType::getNonLValueExprType(const ASTContext &Context) const { - if (const ReferenceType *RefType = getTypePtr()->getAs()) + if (const auto *RefType = getTypePtr()->getAs()) return RefType->getPointeeType(); // C++0x [basic.lval]: @@ -2777,7 +2773,7 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef params, FunctionTypeBits.RefQualifier = epi.RefQualifier; // Fill in the trailing argument array. - QualType *argSlot = reinterpret_cast(this+1); + auto *argSlot = reinterpret_cast(this+1); for (unsigned i = 0; i != NumParams; ++i) { if (params[i]->isDependentType()) setDependent(); @@ -2808,7 +2804,7 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef params, } } else if (getExceptionSpecType() == EST_ComputedNoexcept) { // Store the noexcept expression and context. - Expr **noexSlot = reinterpret_cast(argSlot + NumParams); + auto **noexSlot = reinterpret_cast(argSlot + NumParams); *noexSlot = epi.ExceptionSpec.NoexceptExpr; if (epi.ExceptionSpec.NoexceptExpr) { @@ -2822,8 +2818,7 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef params, } else if (getExceptionSpecType() == EST_Uninstantiated) { // Store the function decl from which we will resolve our // exception specification. - FunctionDecl **slot = - reinterpret_cast(argSlot + NumParams); + auto **slot = reinterpret_cast(argSlot + NumParams); slot[0] = epi.ExceptionSpec.SourceDecl; slot[1] = epi.ExceptionSpec.SourceTemplate; // This exception specification doesn't make the type dependent, because @@ -2831,8 +2826,7 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef params, } else if (getExceptionSpecType() == EST_Unevaluated) { // Store the function decl from which we will resolve our // exception specification. - FunctionDecl **slot = - reinterpret_cast(argSlot + NumParams); + auto **slot = reinterpret_cast(argSlot + NumParams); slot[0] = epi.ExceptionSpec.SourceDecl; } @@ -2850,7 +2844,7 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef params, } if (epi.ExtParameterInfos) { - ExtParameterInfo *extParamInfos = + auto *extParamInfos = const_cast(getExtParameterInfosBuffer()); for (unsigned i = 0; i != NumParams; ++i) extParamInfos[i] = epi.ExtParameterInfos[i]; @@ -3093,7 +3087,7 @@ bool RecordType::hasConstFields() const { if (FieldTy.isConstQualified()) return true; FieldTy = FieldTy.getCanonicalType(); - if (const RecordType *FieldRecTy = FieldTy->getAs()) + if (const auto *FieldRecTy = FieldTy->getAs()) if (FieldRecTy->hasConstFields()) return true; } @@ -3276,8 +3270,7 @@ TemplateSpecializationType(TemplateName T, T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && "Unexpected template name for TemplateSpecializationType"); - TemplateArgument *TemplateArgs - = reinterpret_cast(this + 1); + auto *TemplateArgs = reinterpret_cast(this + 1); for (const TemplateArgument &Arg : Args) { // Update instantiation-dependent and variably-modified bits. // If the canonical type exists and is non-dependent, the template @@ -3299,7 +3292,7 @@ TemplateSpecializationType(TemplateName T, // Store the aliased type if this is a type alias template specialization. if (TypeAlias) { - TemplateArgument *Begin = reinterpret_cast(this + 1); + auto *Begin = reinterpret_cast(this + 1); *reinterpret_cast(Begin + getNumArgs()) = AliasedType; } } @@ -3497,7 +3490,7 @@ static CachedProperties computeCachedProperties(const Type *T) { case Type::RValueReference: return Cache::get(cast(T)->getPointeeType()); case Type::MemberPointer: { - const MemberPointerType *MPT = cast(T); + const auto *MPT = cast(T); return merge(Cache::get(MPT->getClass()), Cache::get(MPT->getPointeeType())); } @@ -3511,7 +3504,7 @@ static CachedProperties computeCachedProperties(const Type *T) { case Type::FunctionNoProto: return Cache::get(cast(T)->getReturnType()); case Type::FunctionProto: { - const FunctionProtoType *FPT = cast(T); + const auto *FPT = cast(T); CachedProperties result = Cache::get(FPT->getReturnType()); for (const auto &ai : FPT->param_types()) result = merge(result, Cache::get(ai)); @@ -3581,7 +3574,7 @@ LinkageInfo LinkageComputer::computeTypeLinkageInfo(const Type *T) { case Type::RValueReference: return computeTypeLinkageInfo(cast(T)->getPointeeType()); case Type::MemberPointer: { - const MemberPointerType *MPT = cast(T); + const auto *MPT = cast(T); LinkageInfo LV = computeTypeLinkageInfo(MPT->getClass()); LV.merge(computeTypeLinkageInfo(MPT->getPointeeType())); return LV; @@ -3596,7 +3589,7 @@ LinkageInfo LinkageComputer::computeTypeLinkageInfo(const Type *T) { case Type::FunctionNoProto: return computeTypeLinkageInfo(cast(T)->getReturnType()); case Type::FunctionProto: { - const FunctionProtoType *FPT = cast(T); + const auto *FPT = cast(T); LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType()); for (const auto &ai : FPT->param_types()) LV.merge(computeTypeLinkageInfo(ai)); @@ -3791,7 +3784,7 @@ Optional AttributedType::stripOuterNullability(QualType &T) { } bool Type::isBlockCompatibleObjCPointerType(ASTContext &ctx) const { - const ObjCObjectPointerType *objcPtr = getAs(); + const auto *objcPtr = getAs(); if (!objcPtr) return false; @@ -3836,11 +3829,10 @@ bool Type::isObjCARCImplicitlyUnretainedType() const { const Type *canon = getCanonicalTypeInternal().getTypePtr(); // Walk down to the base type. We don't care about qualifiers for this. - while (const ArrayType *array = dyn_cast(canon)) + while (const auto *array = dyn_cast(canon)) canon = array->getElementType().getTypePtr(); - if (const ObjCObjectPointerType *opt - = dyn_cast(canon)) { + if (const auto *opt = dyn_cast(canon)) { // Class and Class don't require retention. if (opt->getObjectType()->isObjCClass()) return true; @@ -3852,7 +3844,7 @@ bool Type::isObjCARCImplicitlyUnretainedType() const { bool Type::isObjCNSObjectType() const { const Type *cur = this; while (true) { - if (const TypedefType *typedefType = dyn_cast(cur)) + if (const auto *typedefType = dyn_cast(cur)) return typedefType->getDecl()->hasAttr(); // Single-step desugar until we run out of sugar. @@ -3863,7 +3855,7 @@ bool Type::isObjCNSObjectType() const { } bool Type::isObjCIndependentClassType() const { - if (const TypedefType *typedefType = dyn_cast(this)) + if (const auto *typedefType = dyn_cast(this)) return typedefType->getDecl()->hasAttr(); return false; } @@ -3877,11 +3869,11 @@ bool Type::isObjCRetainableType() const { bool Type::isObjCIndirectLifetimeType() const { if (isObjCLifetimeType()) return true; - if (const PointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->getPointeeType()->isObjCIndirectLifetimeType(); - if (const ReferenceType *Ref = getAs()) + if (const auto *Ref = getAs()) return Ref->getPointeeType()->isObjCIndirectLifetimeType(); - if (const MemberPointerType *MemPtr = getAs()) + if (const auto *MemPtr = getAs()) return MemPtr->getPointeeType()->isObjCIndirectLifetimeType(); return false; } @@ -3903,7 +3895,7 @@ bool Type::isObjCARCBridgableType() const { /// \brief Determine whether the given type T is a "bridgeable" C type. bool Type::isCARCBridgableType() const { - const PointerType *Pointer = getAs(); + const auto *Pointer = getAs(); if (!Pointer) return false; @@ -3914,9 +3906,9 @@ bool Type::isCARCBridgableType() const { bool Type::hasSizedVLAType() const { if (!isVariablyModifiedType()) return false; - if (const PointerType *ptr = getAs()) + if (const auto *ptr = getAs()) return ptr->getPointeeType()->hasSizedVLAType(); - if (const ReferenceType *ref = getAs()) + if (const auto *ref = getAs()) return ref->getPointeeType()->hasSizedVLAType(); if (const ArrayType *arr = getAsArrayTypeUnsafe()) { if (isa(arr) && -- 2.40.0