Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -76,6 +76,7 @@ using llvm::make_error; using llvm::Error; using llvm::Expected; + using ExpectedTypePtr = llvm::Expected; using ExpectedType = llvm::Expected; using ExpectedStmt = llvm::Expected; using ExpectedExpr = llvm::Expected; @@ -160,7 +161,9 @@ // Call the import function of ASTImporter for a baseclass of type `T` and // cast the return value to `T`. template - Expected import(T *From) { + auto import(T *From) + -> std::conditional_t::value, + Expected, Expected> { auto ToOrErr = Importer.Import(From); if (!ToOrErr) return ToOrErr.takeError(); @@ -168,7 +171,7 @@ } template - Expected import(const T *From) { + auto import(const T *From) { return import(const_cast(From)); } @@ -1164,12 +1167,12 @@ if (!ToPointeeTypeOrErr) return ToPointeeTypeOrErr.takeError(); - ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); + ExpectedTypePtr ClassTypeOrErr = import(T->getClass()); if (!ClassTypeOrErr) return ClassTypeOrErr.takeError(); - return Importer.getToContext().getMemberPointerType( - *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); + return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr, + *ClassTypeOrErr); } ExpectedType @@ -1475,34 +1478,32 @@ ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( const SubstTemplateTypeParmType *T) { - ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); + Expected ReplacedOrErr = + import(T->getReplacedParameter()); if (!ReplacedOrErr) return ReplacedOrErr.takeError(); - const TemplateTypeParmType *Replaced = - cast((*ReplacedOrErr).getTypePtr()); ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); if (!ToReplacementTypeOrErr) return ToReplacementTypeOrErr.takeError(); return Importer.getToContext().getSubstTemplateTypeParmType( - Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); + *ReplacedOrErr, ToReplacementTypeOrErr->getCanonicalType()); } ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType( const SubstTemplateTypeParmPackType *T) { - ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); + Expected ReplacedOrErr = + import(T->getReplacedParameter()); if (!ReplacedOrErr) return ReplacedOrErr.takeError(); - const TemplateTypeParmType *Replaced = - cast(ReplacedOrErr->getTypePtr()); Expected ToArgumentPack = import(T->getArgumentPack()); if (!ToArgumentPack) return ToArgumentPack.takeError(); return Importer.getToContext().getSubstTemplateTypeParmPackType( - Replaced, *ToArgumentPack); + *ReplacedOrErr, *ToArgumentPack); } ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( @@ -1517,7 +1518,7 @@ return std::move(Err); QualType ToCanonType; - if (!QualType(T, 0).isCanonical()) { + if (!T->isCanonicalUnqualified()) { QualType FromCanonType = Importer.getFromContext().getCanonicalType(QualType(T, 0)); if (ExpectedType TyOrErr = import(FromCanonType)) @@ -8378,7 +8379,7 @@ return make_error(ImportError::UnsupportedConstruct); } -Expected ASTImporter::Import(const Type *FromT) { +ExpectedTypePtr ASTImporter::Import(const Type *FromT) { if (!FromT) return FromT; @@ -8388,7 +8389,7 @@ if (Pos != ImportedTypes.end()) return Pos->second; - // Import the type + // Import the type. ASTNodeImporter Importer(*this); ExpectedType ToTOrErr = Importer.Visit(FromT); if (!ToTOrErr) @@ -8404,7 +8405,7 @@ if (FromT.isNull()) return QualType{}; - Expected ToTyOrErr = Import(FromT.getTypePtr()); + ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr()); if (!ToTyOrErr) return ToTyOrErr.takeError(); @@ -8904,12 +8905,11 @@ case NestedNameSpecifier::TypeSpec: case NestedNameSpecifier::TypeSpecWithTemplate: - if (Expected TyOrErr = - Import(QualType(FromNNS->getAsType(), 0u))) { + if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) { bool TSTemplate = FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, - TyOrErr->getTypePtr()); + *TyOrErr); } else { return TyOrErr.takeError(); } @@ -9544,16 +9544,14 @@ } } else { FromElemTy = FromValue.getLValueBase().getTypeInfoType(); - QualType ImpTypeInfo = importChecked( - Err, - QualType(FromValue.getLValueBase().get().getType(), - 0)); + const Type *ImpTypeInfo = importChecked( + Err, FromValue.getLValueBase().get().getType()); QualType ImpType = importChecked(Err, FromValue.getLValueBase().getTypeInfoType()); if (Err) return std::move(Err); - Base = APValue::LValueBase::getTypeInfo( - TypeInfoLValue(ImpTypeInfo.getTypePtr()), ImpType); + Base = APValue::LValueBase::getTypeInfo(TypeInfoLValue(ImpTypeInfo), + ImpType); } } CharUnits Offset = FromValue.getLValueOffset();