diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp index 310b5bf9affa1..6d7d1d6b87c60 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp @@ -53,7 +53,7 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) { if (const auto Dep = TheType.getAs()) { const IdentifierInfo *Identifier = Dep.getTypePtr()->getIdentifier(); if (!Identifier || Identifier->getName() != "type" || - Dep.getTypePtr()->getKeyword() != ETK_Typename) { + Dep.getTypePtr()->getKeyword() != ElaboratedTypeKeyword::Typename) { return std::nullopt; } TheType = Dep.getQualifierLoc().getTypeLoc(); @@ -105,7 +105,7 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) { if (const auto *AliasedType = dyn_cast(Specialization->getAliasedType())) { if (AliasedType->getIdentifier()->getName() != "type" || - AliasedType->getKeyword() != ETK_Typename) { + AliasedType->getKeyword() != ElaboratedTypeKeyword::Typename) { return std::nullopt; } } else { diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp index 5a456c58fb5cc..9774e988d71e2 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp @@ -98,7 +98,8 @@ struct UnqualNameVisitor : public RecursiveASTVisitor { return false; const auto *T = TL.getTypePtr(); return TraverseTypeLoc(TL.getNamedTypeLoc(), - T->getKeyword() != ETK_None || T->getQualifier()); + T->getKeyword() != ElaboratedTypeKeyword::None || + T->getQualifier()); } bool VisitDeclRefExpr(DeclRefExpr *S) { diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 080a5b045ed4d..233f607849ce7 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1575,6 +1575,32 @@ enum class AutoTypeKeyword { /// 'static' is only allowed on function parameters. enum class ArraySizeModifier { Normal, Static, Star }; +/// The elaboration keyword that precedes a qualified type name or +/// introduces an elaborated-type-specifier. +enum class ElaboratedTypeKeyword { + /// The "struct" keyword introduces the elaborated-type-specifier. + Struct, + + /// The "__interface" keyword introduces the elaborated-type-specifier. + Interface, + + /// The "union" keyword introduces the elaborated-type-specifier. + Union, + + /// The "class" keyword introduces the elaborated-type-specifier. + Class, + + /// The "enum" keyword introduces the elaborated-type-specifier. + Enum, + + /// The "typename" keyword precedes the qualified type name, e.g., + /// \c typename T::type. + Typename, + + /// No keyword precedes the qualified type name. + None +}; + /// The base class of the type hierarchy. /// /// A central concept with types is that each type always has a canonical @@ -5659,32 +5685,6 @@ enum TagTypeKind { TTK_Enum }; -/// The elaboration keyword that precedes a qualified type name or -/// introduces an elaborated-type-specifier. -enum ElaboratedTypeKeyword { - /// The "struct" keyword introduces the elaborated-type-specifier. - ETK_Struct, - - /// The "__interface" keyword introduces the elaborated-type-specifier. - ETK_Interface, - - /// The "union" keyword introduces the elaborated-type-specifier. - ETK_Union, - - /// The "class" keyword introduces the elaborated-type-specifier. - ETK_Class, - - /// The "enum" keyword introduces the elaborated-type-specifier. - ETK_Enum, - - /// The "typename" keyword precedes the qualified type name, e.g., - /// \c typename T::type. - ETK_Typename, - - /// No keyword precedes the qualified type name. - ETK_None -}; - /// A helper class for Type nodes having an ElaboratedTypeKeyword. /// The keyword in stored in the free bits of the base class. /// Also provides a few static helpers for converting and printing @@ -5694,7 +5694,7 @@ class TypeWithKeyword : public Type { TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, TypeDependence Dependence) : Type(tc, Canonical, Dependence) { - TypeWithKeywordBits.Keyword = Keyword; + TypeWithKeywordBits.Keyword = llvm::to_underlying(Keyword); } public: @@ -5800,7 +5800,7 @@ class ElaboratedType final static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl) { - ID.AddInteger(Keyword); + ID.AddInteger(llvm::to_underlying(Keyword)); ID.AddPointer(NNS); NamedType.Profile(ID); ID.AddPointer(OwnedTagDecl); @@ -5859,7 +5859,7 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name) { - ID.AddInteger(Keyword); + ID.AddInteger(llvm::to_underlying(Keyword)); ID.AddPointer(NNS); ID.AddPointer(Name); } diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h index 5bb487f1a7f44..471deb14aba51 100644 --- a/clang/include/clang/AST/TypeLoc.h +++ b/clang/include/clang/AST/TypeLoc.h @@ -2294,7 +2294,7 @@ class ElaboratedTypeLoc : public ConcreteTypeLocgetNamedType(); } bool isEmpty() const { - return getTypePtr()->getKeyword() == ElaboratedTypeKeyword::ETK_None && + return getTypePtr()->getKeyword() == ElaboratedTypeKeyword::None && !getTypePtr()->getQualifier(); } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e64bb0cf29dbb..e864886a84007 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -5122,7 +5122,8 @@ ASTContext::getDependentTemplateSpecializationType( NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); ElaboratedTypeKeyword CanonKeyword = Keyword; - if (Keyword == ETK_None) CanonKeyword = ETK_Typename; + if (Keyword == ElaboratedTypeKeyword::None) + CanonKeyword = ElaboratedTypeKeyword::Typename; bool AnyNonCanonArgs = false; auto CanonArgs = @@ -12502,7 +12503,7 @@ static auto getCommonTemplateArguments(ASTContext &Ctx, template static ElaboratedTypeKeyword getCommonTypeKeyword(const T *X, const T *Y) { return X->getKeyword() == Y->getKeyword() ? X->getKeyword() - : ElaboratedTypeKeyword::ETK_None; + : ElaboratedTypeKeyword::None; } template diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 8ad142ff09b78..6bb4bf14b873d 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1173,7 +1173,9 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, case Type::Elaborated: { const auto *Elab1 = cast(T1); const auto *Elab2 = cast(T2); - // CHECKME: what if a keyword is ETK_None or ETK_typename ? + // CHECKME: what if a keyword is ElaboratedTypeKeyword::None or + // ElaboratedTypeKeyword::Typename + // ? if (Elab1->getKeyword() != Elab2->getKeyword()) return false; if (!IsStructurallyEquivalent(Context, Elab1->getQualifier(), diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 5efd23a38e739..80a177eb39625 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -4209,20 +4209,20 @@ void CXXNameMangler::mangleType(const DependentNameType *T) { // ::= Te # dependent elaborated type specifier using // # 'enum' switch (T->getKeyword()) { - case ETK_None: - case ETK_Typename: - break; - case ETK_Struct: - case ETK_Class: - case ETK_Interface: - Out << "Ts"; - break; - case ETK_Union: - Out << "Tu"; - break; - case ETK_Enum: - Out << "Te"; - break; + case ElaboratedTypeKeyword::None: + case ElaboratedTypeKeyword::Typename: + break; + case ElaboratedTypeKeyword::Struct: + case ElaboratedTypeKeyword::Class: + case ElaboratedTypeKeyword::Interface: + Out << "Ts"; + break; + case ElaboratedTypeKeyword::Union: + Out << "Tu"; + break; + case ElaboratedTypeKeyword::Enum: + Out << "Te"; + break; } // Typename types are always nested Out << 'N'; diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp index 22bd914c02687..ce2eb96a651e3 100644 --- a/clang/lib/AST/ODRHash.cpp +++ b/clang/lib/AST/ODRHash.cpp @@ -1181,7 +1181,7 @@ class ODRTypeVisitor : public TypeVisitor { } void VisitTypeWithKeyword(const TypeWithKeyword *T) { - ID.AddInteger(T->getKeyword()); + ID.AddInteger(llvm::to_underlying(T->getKeyword())); VisitType(T); }; diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp index 7557336f0aafa..066377423df76 100644 --- a/clang/lib/AST/QualTypeNames.cpp +++ b/clang/lib/AST/QualTypeNames.cpp @@ -440,7 +440,7 @@ QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, // elaborated type. Qualifiers PrefixQualifiers = QT.getLocalQualifiers(); QT = QualType(QT.getTypePtr(), 0); - ElaboratedTypeKeyword Keyword = ETK_None; + ElaboratedTypeKeyword Keyword = ElaboratedTypeKeyword::None; if (const auto *ETypeInput = dyn_cast(QT.getTypePtr())) { QT = ETypeInput->getNamedType(); assert(!QT.hasLocalQualifiers()); @@ -471,7 +471,7 @@ QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, Ctx, QT.getTypePtr(), WithGlobalNsPrefix); QT = QualType(TypePtr, 0); } - if (Prefix || Keyword != ETK_None) { + if (Prefix || Keyword != ElaboratedTypeKeyword::None) { QT = Ctx.getElaboratedType(Keyword, Prefix, QT); } QT = Ctx.getQualifiedType(QT, PrefixQualifiers); diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 2a89b20771543..5b70380d4ad2e 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3016,13 +3016,20 @@ bool Type::isSpecifierType() const { ElaboratedTypeKeyword TypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { switch (TypeSpec) { - default: return ETK_None; - case TST_typename: return ETK_Typename; - case TST_class: return ETK_Class; - case TST_struct: return ETK_Struct; - case TST_interface: return ETK_Interface; - case TST_union: return ETK_Union; - case TST_enum: return ETK_Enum; + default: + return ElaboratedTypeKeyword::None; + case TST_typename: + return ElaboratedTypeKeyword::Typename; + case TST_class: + return ElaboratedTypeKeyword::Class; + case TST_struct: + return ElaboratedTypeKeyword::Struct; + case TST_interface: + return ElaboratedTypeKeyword::Interface; + case TST_union: + return ElaboratedTypeKeyword::Union; + case TST_enum: + return ElaboratedTypeKeyword::Enum; } } @@ -3042,11 +3049,16 @@ TypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { ElaboratedTypeKeyword TypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { switch (Kind) { - case TTK_Class: return ETK_Class; - case TTK_Struct: return ETK_Struct; - case TTK_Interface: return ETK_Interface; - case TTK_Union: return ETK_Union; - case TTK_Enum: return ETK_Enum; + case TTK_Class: + return ElaboratedTypeKeyword::Class; + case TTK_Struct: + return ElaboratedTypeKeyword::Struct; + case TTK_Interface: + return ElaboratedTypeKeyword::Interface; + case TTK_Union: + return ElaboratedTypeKeyword::Union; + case TTK_Enum: + return ElaboratedTypeKeyword::Enum; } llvm_unreachable("Unknown tag type kind."); } @@ -3054,13 +3066,18 @@ TypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { TagTypeKind TypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { switch (Keyword) { - case ETK_Class: return TTK_Class; - case ETK_Struct: return TTK_Struct; - case ETK_Interface: return TTK_Interface; - case ETK_Union: return TTK_Union; - case ETK_Enum: return TTK_Enum; - case ETK_None: // Fall through. - case ETK_Typename: + case ElaboratedTypeKeyword::Class: + return TTK_Class; + case ElaboratedTypeKeyword::Struct: + return TTK_Struct; + case ElaboratedTypeKeyword::Interface: + return TTK_Interface; + case ElaboratedTypeKeyword::Union: + return TTK_Union; + case ElaboratedTypeKeyword::Enum: + return TTK_Enum; + case ElaboratedTypeKeyword::None: // Fall through. + case ElaboratedTypeKeyword::Typename: llvm_unreachable("Elaborated type keyword is not a tag type kind."); } llvm_unreachable("Unknown elaborated type keyword."); @@ -3069,14 +3086,14 @@ TypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { bool TypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { switch (Keyword) { - case ETK_None: - case ETK_Typename: + case ElaboratedTypeKeyword::None: + case ElaboratedTypeKeyword::Typename: return false; - case ETK_Class: - case ETK_Struct: - case ETK_Interface: - case ETK_Union: - case ETK_Enum: + case ElaboratedTypeKeyword::Class: + case ElaboratedTypeKeyword::Struct: + case ElaboratedTypeKeyword::Interface: + case ElaboratedTypeKeyword::Union: + case ElaboratedTypeKeyword::Enum: return true; } llvm_unreachable("Unknown elaborated type keyword."); @@ -3084,13 +3101,20 @@ TypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { StringRef TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { switch (Keyword) { - case ETK_None: return {}; - case ETK_Typename: return "typename"; - case ETK_Class: return "class"; - case ETK_Struct: return "struct"; - case ETK_Interface: return "__interface"; - case ETK_Union: return "union"; - case ETK_Enum: return "enum"; + case ElaboratedTypeKeyword::None: + return {}; + case ElaboratedTypeKeyword::Typename: + return "typename"; + case ElaboratedTypeKeyword::Class: + return "class"; + case ElaboratedTypeKeyword::Struct: + return "struct"; + case ElaboratedTypeKeyword::Interface: + return "__interface"; + case ElaboratedTypeKeyword::Union: + return "union"; + case ElaboratedTypeKeyword::Enum: + return "enum"; } llvm_unreachable("Unknown elaborated type keyword."); @@ -3123,7 +3147,7 @@ DependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *Qualifier, const IdentifierInfo *Name, ArrayRef Args) { - ID.AddInteger(Keyword); + ID.AddInteger(llvm::to_underlying(Keyword)); ID.AddPointer(Qualifier); ID.AddPointer(Name); for (const TemplateArgument &Arg : Args) @@ -4741,7 +4765,7 @@ AutoType::AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef TypeConstraintArgs) : DeducedType(Auto, DeducedAsType, ExtraDependence, Canon) { - AutoTypeBits.Keyword = (unsigned)Keyword; + AutoTypeBits.Keyword = llvm::to_underlying(Keyword); AutoTypeBits.NumArgs = TypeConstraintArgs.size(); this->TypeConstraintConcept = TypeConstraintConcept; assert(TypeConstraintConcept || AutoTypeBits.NumArgs == 0); diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index f6e69b988f41d..c24373b346046 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -1597,7 +1597,7 @@ void TypePrinter::printElaboratedBefore(const ElaboratedType *T, if (!Policy.IncludeTagDefinition) { OS << TypeWithKeyword::getKeywordName(T->getKeyword()); - if (T->getKeyword() != ETK_None) + if (T->getKeyword() != ElaboratedTypeKeyword::None) OS << " "; NestedNameSpecifier *Qualifier = T->getQualifier(); if (Qualifier) @@ -1641,7 +1641,7 @@ void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) { void TypePrinter::printDependentNameBefore(const DependentNameType *T, raw_ostream &OS) { OS << TypeWithKeyword::getKeywordName(T->getKeyword()); - if (T->getKeyword() != ETK_None) + if (T->getKeyword() != ElaboratedTypeKeyword::None) OS << " "; T->getQualifier()->print(OS, Policy); @@ -1658,7 +1658,7 @@ void TypePrinter::printDependentTemplateSpecializationBefore( IncludeStrongLifetimeRAII Strong(Policy); OS << TypeWithKeyword::getKeywordName(T->getKeyword()); - if (T->getKeyword() != ETK_None) + if (T->getKeyword() != ElaboratedTypeKeyword::None) OS << " "; if (T->getQualifier()) diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp index 06552d011a2d4..02fa6cd6119ec 100644 --- a/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -297,7 +297,7 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType( // qualified name, e.g., `N::M::type`, or both. if (const ElaboratedType *ET = dyn_cast(T)) { ElaboratedTypeKeyword Keyword = ET->getKeyword(); - if (Keyword != ETK_None) { + if (Keyword != ElaboratedTypeKeyword::None) { Fragments .append(ElaboratedType::getKeywordName(Keyword), DeclarationFragments::FragmentKind::Keyword) diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index f37ba5cf4c109..44a40215b90df 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -908,7 +908,7 @@ bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, // the template name. assert(DTN->getQualifier() == SS.getScopeRep()); QualType T = Context.getDependentTemplateSpecializationType( - ETK_None, DTN->getQualifier(), DTN->getIdentifier(), + ElaboratedTypeKeyword::None, DTN->getQualifier(), DTN->getIdentifier(), TemplateArgs.arguments()); // Create source-location information for this type. diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index cfaa93fbea4dd..38ac406b14ada 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -118,7 +118,8 @@ static QualType lookupPromiseType(Sema &S, const FunctionDecl *FD, auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, S.getStdNamespace()); NNS = NestedNameSpecifier::Create(S.Context, NNS, false, CoroTrait.getTypePtr()); - return S.Context.getElaboratedType(ETK_None, NNS, PromiseType); + return S.Context.getElaboratedType(ElaboratedTypeKeyword::None, NNS, + PromiseType); }; if (!PromiseType->getAsCXXRecordDecl()) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d1550f1289068..824267acbb1c0 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -266,7 +266,8 @@ static ParsedType recoverFromTypeInKnownDependentBase(Sema &S, ASTContext &Context = S.Context; auto *NNS = NestedNameSpecifier::Create(Context, nullptr, false, cast(Context.getRecordType(RD))); - QualType T = Context.getDependentNameType(ETK_Typename, NNS, &II); + QualType T = + Context.getDependentNameType(ElaboratedTypeKeyword::Typename, NNS, &II); CXXScopeSpec SS; SS.MakeTrivial(Context, NNS, SourceRange(NameLoc)); @@ -303,10 +304,10 @@ static ParsedType buildNamedType(Sema &S, const CXXScopeSpec *SS, QualType T, } if (!SS || SS->isEmpty()) - return ParsedType::make( - S.Context.getElaboratedType(ETK_None, nullptr, T, nullptr)); + return ParsedType::make(S.Context.getElaboratedType( + ElaboratedTypeKeyword::None, nullptr, T, nullptr)); - QualType ElTy = S.getElaboratedType(ETK_None, *SS, T); + QualType ElTy = S.getElaboratedType(ElaboratedTypeKeyword::None, *SS, T); if (!WantNontrivialTypeSourceInfo) return ParsedType::make(ElTy); @@ -383,9 +384,10 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, .get(); NestedNameSpecifierLoc QualifierLoc = SS->getWithLocInContext(Context); - QualType T = - CheckTypenameType(IsImplicitTypename ? ETK_Typename : ETK_None, - SourceLocation(), QualifierLoc, II, NameLoc); + QualType T = CheckTypenameType( + IsImplicitTypename ? ElaboratedTypeKeyword::Typename + : ElaboratedTypeKeyword::None, + SourceLocation(), QualifierLoc, II, NameLoc); return ParsedType::make(T); } @@ -648,7 +650,8 @@ ParsedType Sema::ActOnMSVCUnknownTypeName(const IdentifierInfo &II, return ParsedType(); } - QualType T = Context.getDependentNameType(ETK_None, NNS, &II); + QualType T = + Context.getDependentNameType(ElaboratedTypeKeyword::None, NNS, &II); // Build type location information. We synthesized the qualifier, so we have // to build a fake NestedNameSpecifierLoc. diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index beb7e5b177c6e..5b6d452ebf4ea 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -4511,9 +4511,9 @@ Sema::BuildMemInitializer(Decl *ConstructorD, if (!NotUnknownSpecialization) { // When the scope specifier can refer to a member of an unknown // specialization, we take it as a type name. - BaseType = CheckTypenameType(ETK_None, SourceLocation(), - SS.getWithLocInContext(Context), - *MemberOrBase, IdLoc); + BaseType = CheckTypenameType( + ElaboratedTypeKeyword::None, SourceLocation(), + SS.getWithLocInContext(Context), *MemberOrBase, IdLoc); if (BaseType.isNull()) return true; @@ -4596,7 +4596,8 @@ Sema::BuildMemInitializer(Decl *ConstructorD, } if (BaseType.isNull()) { - BaseType = getElaboratedType(ETK_None, SS, Context.getTypeDeclType(TyD)); + BaseType = getElaboratedType(ElaboratedTypeKeyword::None, SS, + Context.getTypeDeclType(TyD)); MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false); TInfo = Context.CreateTypeSourceInfo(BaseType); ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs(); @@ -7727,7 +7728,8 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, QualType ThisType = MD->getFunctionObjectParameterType(); QualType DeclType = Context.getTypeDeclType(RD); - DeclType = Context.getElaboratedType(ETK_None, nullptr, DeclType, nullptr); + DeclType = Context.getElaboratedType(ElaboratedTypeKeyword::None, nullptr, + DeclType, nullptr); DeclType = Context.getAddrSpaceQualType( DeclType, ThisType.getQualifiers().getAddressSpace()); QualType ExpectedReturnType = Context.getLValueReferenceType(DeclType); @@ -11836,7 +11838,8 @@ QualType Sema::CheckComparisonCategoryType(ComparisonCategoryType Kind, auto TyForDiags = [&](ComparisonCategoryInfo *Info) { auto *NNS = NestedNameSpecifier::Create(Context, nullptr, getStdNamespace()); - return Context.getElaboratedType(ETK_None, NNS, Info->getType()); + return Context.getElaboratedType(ElaboratedTypeKeyword::None, NNS, + Info->getType()); }; // Check if we've already successfully checked the comparison category type @@ -12055,7 +12058,7 @@ QualType Sema::BuildStdInitializerList(QualType Element, SourceLocation Loc) { Context.getTrivialTypeSourceInfo(Element, Loc))); return Context.getElaboratedType( - ElaboratedTypeKeyword::ETK_None, + ElaboratedTypeKeyword::None, NestedNameSpecifier::Create(Context, nullptr, getStdNamespace()), CheckTemplateIdType(TemplateName(StdInitializerList), Loc, Args)); } @@ -14837,7 +14840,8 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) { return nullptr; QualType ArgType = Context.getTypeDeclType(ClassDecl); - ArgType = Context.getElaboratedType(ETK_None, nullptr, ArgType, nullptr); + ArgType = Context.getElaboratedType(ElaboratedTypeKeyword::None, nullptr, + ArgType, nullptr); LangAS AS = getDefaultCXXMethodAddrSpace(); if (AS != LangAS::Default) ArgType = Context.getAddrSpaceQualType(ArgType, AS); @@ -15190,7 +15194,8 @@ CXXMethodDecl *Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) { // constructor rules. QualType ArgType = Context.getTypeDeclType(ClassDecl); - ArgType = Context.getElaboratedType(ETK_None, nullptr, ArgType, nullptr); + ArgType = Context.getElaboratedType(ElaboratedTypeKeyword::None, nullptr, + ArgType, nullptr); LangAS AS = getDefaultCXXMethodAddrSpace(); if (AS != LangAS::Default) ArgType = Context.getAddrSpaceQualType(ArgType, AS); @@ -15579,7 +15584,8 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor( QualType ClassType = Context.getTypeDeclType(ClassDecl); QualType ArgType = ClassType; - ArgType = Context.getElaboratedType(ETK_None, nullptr, ArgType, nullptr); + ArgType = Context.getElaboratedType(ElaboratedTypeKeyword::None, nullptr, + ArgType, nullptr); bool Const = ClassDecl->implicitCopyConstructorHasConstParam(); if (Const) ArgType = ArgType.withConst(); @@ -15724,7 +15730,8 @@ CXXConstructorDecl *Sema::DeclareImplicitMoveConstructor( QualType ClassType = Context.getTypeDeclType(ClassDecl); QualType ArgType = ClassType; - ArgType = Context.getElaboratedType(ETK_None, nullptr, ArgType, nullptr); + ArgType = Context.getElaboratedType(ElaboratedTypeKeyword::None, nullptr, + ArgType, nullptr); LangAS AS = getDefaultCXXMethodAddrSpace(); if (AS != LangAS::Default) ArgType = Context.getAddrSpaceQualType(ClassType, AS); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 83519476f0742..8d3086cf3962c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2987,7 +2987,7 @@ ExprResult Sema::BuildQualifiedDeclarationNameExpr( TypeLocBuilder TLB; TLB.pushTypeSpec(Ty).setNameLoc(NameInfo.getLoc()); - QualType ET = getElaboratedType(ETK_None, SS, Ty); + QualType ET = getElaboratedType(ElaboratedTypeKeyword::None, SS, Ty); ElaboratedTypeLoc QTL = TLB.push(ET); QTL.setElaboratedKeywordLoc(SourceLocation()); QTL.setQualifierLoc(SS.getWithLocInContext(Context)); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index e977407056218..e350a6a12b2b5 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -72,8 +72,8 @@ ParsedType Sema::getInheritingConstructorName(CXXScopeSpec &SS, // Strip off the last layer of the nested-name-specifier and build a // typename type for it. assert(NNS->getAsIdentifier() == &Name && "not a constructor name"); - Type = Context.getDependentNameType(ETK_None, NNS->getPrefix(), - NNS->getAsIdentifier()); + Type = Context.getDependentNameType( + ElaboratedTypeKeyword::None, NNS->getPrefix(), NNS->getAsIdentifier()); break; case NestedNameSpecifier::Global: @@ -101,7 +101,8 @@ ParsedType Sema::getConstructorName(IdentifierInfo &II, // friend declaration or an inherited constructor declaration), form an // unresolved "typename" type. if (CurClass->isDependentContext() && !EnteringContext && SS.getScopeRep()) { - QualType T = Context.getDependentNameType(ETK_None, SS.getScopeRep(), &II); + QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None, + SS.getScopeRep(), &II); return ParsedType::make(T); } @@ -245,8 +246,9 @@ ParsedType Sema::getDestructorName(IdentifierInfo &II, SourceLocation NameLoc, if (IsAcceptableResult(Type)) { QualType T = Context.getTypeDeclType(Type); MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false); - return CreateParsedType(Context.getElaboratedType(ETK_None, nullptr, T), - Context.getTrivialTypeSourceInfo(T, NameLoc)); + return CreateParsedType( + Context.getElaboratedType(ElaboratedTypeKeyword::None, nullptr, T), + Context.getTrivialTypeSourceInfo(T, NameLoc)); } } @@ -362,9 +364,9 @@ ParsedType Sema::getDestructorName(IdentifierInfo &II, SourceLocation NameLoc, // We didn't find our type, but that's OK: it's dependent anyway. // FIXME: What if we have no nested-name-specifier? - QualType T = CheckTypenameType(ETK_None, SourceLocation(), - SS.getWithLocInContext(Context), - II, NameLoc); + QualType T = + CheckTypenameType(ElaboratedTypeKeyword::None, SourceLocation(), + SS.getWithLocInContext(Context), II, NameLoc); return ParsedType::make(T); } @@ -8943,9 +8945,10 @@ Sema::ActOnTypeRequirement(SourceLocation TypenameKWLoc, CXXScopeSpec &SS, "Exactly one of TypeName and TemplateId must be specified."); TypeSourceInfo *TSI = nullptr; if (TypeName) { - QualType T = CheckTypenameType(ETK_Typename, TypenameKWLoc, - SS.getWithLocInContext(Context), *TypeName, - NameLoc, &TSI, /*DeducedTSTContext=*/false); + QualType T = + CheckTypenameType(ElaboratedTypeKeyword::Typename, TypenameKWLoc, + SS.getWithLocInContext(Context), *TypeName, NameLoc, + &TSI, /*DeducedTSTContext=*/false); if (T.isNull()) return nullptr; } else { diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index c2477ec0063e4..59721c8dc664a 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -3907,7 +3907,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, // correct, or the code is ill-formed and will be diagnosed when the // dependent name is substituted. return Context.getDependentTemplateSpecializationType( - ETK_None, DTN->getQualifier(), DTN->getIdentifier(), + ElaboratedTypeKeyword::None, DTN->getQualifier(), DTN->getIdentifier(), TemplateArgs.arguments()); if (Name.getAsAssumedTemplateName() && @@ -4221,7 +4221,7 @@ TypeResult Sema::ActOnTemplateIdType( if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { assert(SS.getScopeRep() == DTN->getQualifier()); QualType T = Context.getDependentTemplateSpecializationType( - ETK_None, DTN->getQualifier(), DTN->getIdentifier(), + ElaboratedTypeKeyword::None, DTN->getQualifier(), DTN->getIdentifier(), TemplateArgs.arguments()); // Build type-source information. TypeLocBuilder TLB; @@ -4254,8 +4254,9 @@ TypeResult Sema::ActOnTemplateIdType( SpecTL.setArgLocInfo(i, TemplateArgs[i].getLocInfo()); // Create an elaborated-type-specifier containing the nested-name-specifier. - QualType ElTy = getElaboratedType( - ETK_None, !IsCtorOrDtorName ? SS : CXXScopeSpec(), SpecTy); + QualType ElTy = + getElaboratedType(ElaboratedTypeKeyword::None, + !IsCtorOrDtorName ? SS : CXXScopeSpec(), SpecTy); ElaboratedTypeLoc ElabTL = TLB.push(ElTy); ElabTL.setElaboratedKeywordLoc(SourceLocation()); if (!ElabTL.isEmpty()) @@ -5289,8 +5290,8 @@ bool Sema::CheckTemplateTypeArgument( // Recover by synthesizing a type using the location information that we // already have. - ArgType = - Context.getDependentNameType(ETK_Typename, SS.getScopeRep(), II); + ArgType = Context.getDependentNameType(ElaboratedTypeKeyword::Typename, + SS.getScopeRep(), II); TypeLocBuilder TLB; DependentNameTypeLoc TL = TLB.push(ArgType); TL.setElaboratedKeywordLoc(SourceLocation(/*synthesized*/)); @@ -5568,7 +5569,7 @@ convertTypeTemplateArgumentToTemplate(ASTContext &Context, TypeLoc TLoc) { // Extract and step over any surrounding nested-name-specifier. NestedNameSpecifierLoc QualLoc; if (auto ETLoc = TLoc.getAs()) { - if (ETLoc.getTypePtr()->getKeyword() != ETK_None) + if (ETLoc.getTypePtr()->getKeyword() != ElaboratedTypeKeyword::None) return TemplateArgumentLoc(); QualLoc = ETLoc.getQualifierLoc(); @@ -10860,8 +10861,8 @@ TypeResult Sema::ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, QualType T = CheckTypenameType((TypenameLoc.isValid() || IsImplicitTypename == ImplicitTypenameContext::Yes) - ? ETK_Typename - : ETK_None, + ? ElaboratedTypeKeyword::Typename + : ElaboratedTypeKeyword::None, TypenameLoc, QualifierLoc, II, IdLoc, &TSI, /*DeducedTSTContext=*/true); if (T.isNull()) @@ -10910,8 +10911,8 @@ Sema::ActOnTypenameType(Scope *S, assert(DTN && "dependent template has non-dependent name?"); assert(DTN->getQualifier() == SS.getScopeRep()); QualType T = Context.getDependentTemplateSpecializationType( - ETK_Typename, DTN->getQualifier(), DTN->getIdentifier(), - TemplateArgs.arguments()); + ElaboratedTypeKeyword::Typename, DTN->getQualifier(), + DTN->getIdentifier(), TemplateArgs.arguments()); // Create source-location information for this type. TypeLocBuilder Builder; @@ -10943,7 +10944,8 @@ Sema::ActOnTypenameType(Scope *S, for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo()); - T = Context.getElaboratedType(ETK_Typename, SS.getScopeRep(), T); + T = Context.getElaboratedType(ElaboratedTypeKeyword::Typename, + SS.getScopeRep(), T); ElaboratedTypeLoc TL = Builder.push(T); TL.setElaboratedKeywordLoc(TypenameLoc); TL.setQualifierLoc(SS.getWithLocInContext(Context)); @@ -11146,7 +11148,7 @@ Sema::CheckTypenameType(ElaboratedTypeKeyword Keyword, // ignore functions, but that appears to be an oversight. auto *LookupRD = dyn_cast_or_null(Ctx); auto *FoundRD = dyn_cast(Type); - if (Keyword == ETK_Typename && LookupRD && FoundRD && + if (Keyword == ElaboratedTypeKeyword::Typename && LookupRD && FoundRD && FoundRD->isInjectedClassName() && declaresSameEntity(LookupRD, cast(FoundRD->getParent()))) Diag(IILoc, diag::ext_out_of_line_qualified_id_type_names_constructor) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index e09897318ba98..6ad70109c8cee 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1709,7 +1709,8 @@ TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, // TODO: should we even warn on struct/class mismatches for this? Seems // like it's likely to produce a lot of spurious errors. - if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { + if (Id && Keyword != ElaboratedTypeKeyword::None && + Keyword != ElaboratedTypeKeyword::Typename) { TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false, TagLocation, Id)) { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 37491925d750a..dd7065e32a7a5 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5714,8 +5714,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, NestedNameSpecifier *NNSPrefix = NNS->getPrefix(); switch (NNS->getKind()) { case NestedNameSpecifier::Identifier: - ClsType = Context.getDependentNameType(ETK_None, NNSPrefix, - NNS->getAsIdentifier()); + ClsType = Context.getDependentNameType( + ElaboratedTypeKeyword::None, NNSPrefix, NNS->getAsIdentifier()); break; case NestedNameSpecifier::Namespace: @@ -5733,7 +5733,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // NOTE: in particular, no wrap occurs if ClsType already is an // Elaborated, DependentName, or DependentTemplateSpecialization. if (isa(NNS->getAsType())) - ClsType = Context.getElaboratedType(ETK_None, NNSPrefix, ClsType); + ClsType = Context.getElaboratedType(ElaboratedTypeKeyword::None, + NNSPrefix, ClsType); break; } } else { @@ -6333,7 +6334,7 @@ namespace { } } const ElaboratedType *T = TL.getTypePtr(); - TL.setElaboratedKeywordLoc(T->getKeyword() != ETK_None + TL.setElaboratedKeywordLoc(T->getKeyword() != ElaboratedTypeKeyword::None ? DS.getTypeSpecTypeLoc() : SourceLocation()); const CXXScopeSpec& SS = DS.getTypeSpecScope(); diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index e990cc2e60c8d..6e8321e163e1c 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1160,7 +1160,8 @@ class TreeTransform { Id); } - if (Keyword == ETK_None || Keyword == ETK_Typename) { + if (Keyword == ElaboratedTypeKeyword::None || + Keyword == ElaboratedTypeKeyword::Typename) { return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, *Id, IdLoc, DeducedTSTContext); } @@ -7019,7 +7020,8 @@ TreeTransform::TransformElaboratedType(TypeLocBuilder &TLB, // If the identifier resolves to a typedef-name or the simple-template-id // resolves to an alias template specialization, the // elaborated-type-specifier is ill-formed. - if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { + if (T->getKeyword() != ElaboratedTypeKeyword::None && + T->getKeyword() != ElaboratedTypeKeyword::Typename) { if (const TemplateSpecializationType *TST = NamedT->getAs()) { TemplateName Template = TST->getTemplateName();