diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -1753,12 +1753,13 @@ /// Described the kind of function definition (if any) provided for /// a function. -enum FunctionDefinitionKind { - FDK_Declaration, - FDK_Definition, - FDK_Defaulted, - FDK_Deleted +enum class FunctionDefinitionKind : unsigned char { + Declaration, + Definition, + Defaulted, + Deleted }; +using FDK = FunctionDefinitionKind; enum class DeclaratorContext { File, // File scope declaration. @@ -1893,7 +1894,8 @@ Declarator(const DeclSpec &ds, DeclaratorContext C) : DS(ds), Range(ds.getSourceRange()), Context(C), InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), - GroupingParens(false), FunctionDefinition(FDK_Declaration), + GroupingParens(false), + FunctionDefinition(static_cast(FDK::Declaration)), Redeclaration(false), Extension(false), ObjCIvar(false), ObjCWeakProperty(false), InlineStorageUsed(false), Attrs(ds.getAttributePool().getFactory()), AsmLabel(nullptr), @@ -2567,11 +2569,11 @@ void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } void setFunctionDefinitionKind(FunctionDefinitionKind Val) { - FunctionDefinition = Val; + FunctionDefinition = static_cast(Val); } bool isFunctionDefinition() const { - return getFunctionDefinitionKind() != FDK_Declaration; + return getFunctionDefinitionKind() != FDK::Declaration; } FunctionDefinitionKind getFunctionDefinitionKind() const { diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp --- a/clang/lib/Parse/ParseCXXInlineMethods.cpp +++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -108,7 +108,7 @@ // or if we are about to parse function member template then consume // the tokens and store them for parsing at the end of the translation unit. if (getLangOpts().DelayedTemplateParsing && - D.getFunctionDefinitionKind() == FDK_Definition && + D.getFunctionDefinitionKind() == FDK::Definition && !D.getDeclSpec().hasConstexprSpecifier() && !(FnD && FnD->getAsFunction() && FnD->getAsFunction()->getReturnType()->getContainedAutoType()) && diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2707,23 +2707,23 @@ if (getLangOpts().MicrosoftExt && DeclaratorInfo.isDeclarationOfFunction()) TryConsumePureSpecifier(/*AllowDefinition*/ true); - FunctionDefinitionKind DefinitionKind = FDK_Declaration; + FunctionDefinitionKind DefinitionKind = FDK::Declaration; // function-definition: // // In C++11, a non-function declarator followed by an open brace is a // braced-init-list for an in-class member initialization, not an // erroneous function definition. if (Tok.is(tok::l_brace) && !getLangOpts().CPlusPlus11) { - DefinitionKind = FDK_Definition; + DefinitionKind = FDK::Definition; } else if (DeclaratorInfo.isFunctionDeclarator()) { if (Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)) { - DefinitionKind = FDK_Definition; + DefinitionKind = FDK::Definition; } else if (Tok.is(tok::equal)) { const Token &KW = NextToken(); if (KW.is(tok::kw_default)) - DefinitionKind = FDK_Defaulted; + DefinitionKind = FDK::Defaulted; else if (KW.is(tok::kw_delete)) - DefinitionKind = FDK_Deleted; + DefinitionKind = FDK::Deleted; else if (KW.is(tok::code_completion)) { Actions.CodeCompleteAfterFunctionEquals(DeclaratorInfo); cutOffParsing(); @@ -2736,13 +2736,13 @@ // C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains // to a friend declaration, that declaration shall be a definition. if (DeclaratorInfo.isFunctionDeclarator() && - DefinitionKind == FDK_Declaration && DS.isFriendSpecified()) { + DefinitionKind == FDK::Declaration && DS.isFriendSpecified()) { // Diagnose attributes that appear before decl specifier: // [[]] friend int foo(); ProhibitAttributes(FnAttrs); } - if (DefinitionKind != FDK_Declaration) { + if (DefinitionKind != FDK::Declaration) { if (!DeclaratorInfo.isFunctionDeclarator()) { Diag(DeclaratorInfo.getIdentifierLoc(), diag::err_func_def_no_params); ConsumeBrace(); diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -3414,7 +3414,7 @@ // Parse the block-declarator. Declarator DeclaratorInfo(DS, DeclaratorContext::BlockLiteral); - DeclaratorInfo.setFunctionDefinitionKind(FDK_Definition); + DeclaratorInfo.setFunctionDefinitionKind(FDK::Definition); ParseDeclarator(DeclaratorInfo); MaybeParseGNUAttributes(DeclaratorInfo); @@ -3453,7 +3453,7 @@ // Parse the return type if present. DeclSpec DS(AttrFactory); Declarator ParamInfo(DS, DeclaratorContext::BlockLiteral); - ParamInfo.setFunctionDefinitionKind(FDK_Definition); + ParamInfo.setFunctionDefinitionKind(FDK::Definition); // FIXME: Since the return type isn't actually parsed, it can't be used to // fill ParamInfo with an initial valid range, so do it manually. ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation())); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1228,7 +1228,7 @@ Scope::CompoundStmtScope); Scope *ParentScope = getCurScope()->getParent(); - D.setFunctionDefinitionKind(FDK_Definition); + D.setFunctionDefinitionKind(FDK::Definition); Decl *DP = Actions.HandleDeclarator(ParentScope, D, TemplateParameterLists); D.complete(DP); @@ -1259,7 +1259,7 @@ Scope::CompoundStmtScope); Scope *ParentScope = getCurScope()->getParent(); - D.setFunctionDefinitionKind(FDK_Definition); + D.setFunctionDefinitionKind(FDK::Definition); Decl *FuncDecl = Actions.HandleDeclarator(ParentScope, D, MultiTemplateParamsArg()); D.complete(FuncDecl); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5543,7 +5543,7 @@ } Decl *Sema::ActOnDeclarator(Scope *S, Declarator &D) { - D.setFunctionDefinitionKind(FDK_Declaration); + D.setFunctionDefinitionKind(FDK::Declaration); Decl *Dcl = HandleDeclarator(S, D, MultiTemplateParamsArg()); if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() && @@ -9160,15 +9160,15 @@ // If a function is defined as defaulted or deleted, mark it as such now. // We'll do the relevant checks on defaulted / deleted functions later. switch (D.getFunctionDefinitionKind()) { - case FDK_Declaration: - case FDK_Definition: + case FDK::Declaration: + case FDK::Definition: break; - case FDK_Defaulted: + case FDK::Defaulted: NewFD->setDefaulted(); break; - case FDK_Deleted: + case FDK::Deleted: NewFD->setDeletedAsWritten(); break; } @@ -9871,17 +9871,17 @@ // because Sema::ActOnStartOfFunctionDef has not been called yet. if (const auto *NBA = NewFD->getAttr()) switch (D.getFunctionDefinitionKind()) { - case FDK_Defaulted: - case FDK_Deleted: + case FDK::Defaulted: + case FDK::Deleted: Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_defaulted_deleted_function) << NBA->getSpelling(); break; - case FDK_Declaration: + case FDK::Declaration: Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_non_definition) << NBA->getSpelling(); break; - case FDK_Definition: + case FDK::Definition: break; } @@ -13786,7 +13786,7 @@ ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( ParentScope, D, TemplateParameterLists, Bases); - D.setFunctionDefinitionKind(FDK_Definition); + D.setFunctionDefinitionKind(FDK::Definition); Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists); Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -5939,7 +5939,7 @@ llvm::omp::TraitProperty::implementation_extension_disable_implicit_base); // If no base was found we create a declaration that we use as base. if (Bases.empty() && UseImplicitBase) { - D.setFunctionDefinitionKind(FDK_Declaration); + D.setFunctionDefinitionKind(FDK::Declaration); Decl *BaseD = HandleDeclarator(S, D, TemplateParamLists); BaseD->setImplicit(true); if (auto *BaseTemplD = dyn_cast(BaseD)) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -3577,7 +3577,7 @@ // Only warn if this declarator is declaring a function at block scope, and // doesn't have a storage class (such as 'extern') specified. if (!D.isFunctionDeclarator() || - D.getFunctionDefinitionKind() != FDK_Declaration || + D.getFunctionDefinitionKind() != FDK::Declaration || !S.CurContext->isFunctionOrMethod() || D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_unspecified) @@ -5034,7 +5034,7 @@ !(S.getLangOpts().CPlusPlus && (T->isDependentType() || T->isRecordType()))) { if (T->isVoidType() && !S.getLangOpts().CPlusPlus && - D.getFunctionDefinitionKind() == FDK_Definition) { + D.getFunctionDefinitionKind() == FDK::Definition) { // [6.9.1/3] qualified void return is invalid on a C // function definition. Apparently ok on declarations and // in C++ though (!) @@ -5405,7 +5405,8 @@ // The empty list in a function declarator that is not part of a definition // of that function specifies that no information about the number or types // of the parameters is supplied. - if (!LangOpts.CPlusPlus && D.getFunctionDefinitionKind() == FDK_Declaration) { + if (!LangOpts.CPlusPlus && + D.getFunctionDefinitionKind() == FDK::Declaration) { bool IsBlock = false; for (const DeclaratorChunk &DeclType : D.type_objects()) { switch (DeclType.Kind) {