From: Faisal Vali Date: Sat, 1 Apr 2017 21:30:49 +0000 (+0000) Subject: [NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped Enum X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=919ac41f651d6e5a1b6391d4c4c07c077e9e9ddb;p=clang [NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped Enum - also replace direct equality checks against the ConstantEvaluated enumerator with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17. - update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299316 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 5ca2cce392..e23c93f99b 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -681,7 +681,8 @@ public: : S(S), SavedContext(S, DC) { S.PushFunctionScope(); - S.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); + S.PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::PotentiallyEvaluated); } ~SynthesizedFunctionScope() { @@ -802,7 +803,7 @@ public: /// \brief Describes how the expressions currently being parsed are /// evaluated at run-time, if at all. - enum ExpressionEvaluationContext { + enum class ExpressionEvaluationContext { /// \brief The current expression and its subexpressions occur within an /// unevaluated operand (C++11 [expr]p7), such as the subexpression of /// \c sizeof, where the type of the expression may be significant but @@ -908,8 +909,12 @@ public: MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx); bool isUnevaluated() const { - return Context == Unevaluated || Context == UnevaluatedAbstract || - Context == UnevaluatedList; + return Context == ExpressionEvaluationContext::Unevaluated || + Context == ExpressionEvaluationContext::UnevaluatedAbstract || + Context == ExpressionEvaluationContext::UnevaluatedList; + } + bool isConstantEvaluated() const { + return Context == ExpressionEvaluationContext::ConstantEvaluated; } }; @@ -10315,6 +10320,7 @@ class EnterExpressionEvaluationContext { bool Entered = true; public: + EnterExpressionEvaluationContext(Sema &Actions, Sema::ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, @@ -10345,8 +10351,8 @@ public: // a context. if (ShouldEnter && Actions.isUnevaluatedContext() && Actions.getLangOpts().CPlusPlus11) { - Actions.PushExpressionEvaluationContext(Sema::UnevaluatedList, nullptr, - false); + Actions.PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::UnevaluatedList, nullptr, false); Entered = true; } } diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index 5034f28f8c..172b0edce5 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -344,9 +344,9 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { // The argument isn't actually potentially evaluated unless it is // used. - EnterExpressionEvaluationContext Eval(Actions, - Sema::PotentiallyEvaluatedIfUsed, - Param); + EnterExpressionEvaluationContext Eval( + Actions, + Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, Param); ExprResult DefArgResult; if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 3531ca4724..85ac71f296 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -308,7 +308,9 @@ unsigned Parser::ParseAttributeArgsCommon( do { bool Uneval = attributeParsedArgsUnevaluated(*AttrName); EnterExpressionEvaluationContext Unevaluated( - Actions, Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated, + Actions, + Uneval ? Sema::ExpressionEvaluationContext::Unevaluated + : Sema::ExpressionEvaluationContext::ConstantEvaluated, /*LambdaContextDecl=*/nullptr, /*IsDecltype=*/false); @@ -4093,8 +4095,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, // anything that's a simple-type-specifier followed by '(' as an // expression. This suffices because function types are not valid // underlying types anyway. - EnterExpressionEvaluationContext Unevaluated(Actions, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); TPResult TPR = isExpressionOrTypeSpecifierSimple(NextToken().getKind()); // If the next token starts an expression, we know we're parsing a // bit-field. This is the common case. @@ -6270,9 +6272,10 @@ void Parser::ParseParameterDeclarationClause( // The argument isn't actually potentially evaluated unless it is // used. - EnterExpressionEvaluationContext Eval(Actions, - Sema::PotentiallyEvaluatedIfUsed, - Param); + EnterExpressionEvaluationContext Eval( + Actions, + Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, + Param); ExprResult DefArgResult; if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { @@ -6422,8 +6425,8 @@ void Parser::ParseBracketDeclarator(Declarator &D) { if (getLangOpts().CPlusPlus) { NumElements = ParseConstantExpression(); } else { - EnterExpressionEvaluationContext Unevaluated(Actions, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); NumElements = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); } @@ -6558,8 +6561,9 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { const bool hasParens = Tok.is(tok::l_paren); - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); bool isCastExpr; ParsedType CastTy; diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 343b5f1a17..ca60d3ff29 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -935,8 +935,9 @@ SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) { // C++11 [dcl.type.simple]p4: // The operand of the decltype specifier is an unevaluated operand. - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, - nullptr,/*IsDecltype=*/true); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, + /*IsDecltype=*/true); Result = Actions.CorrectDelayedTyposInExpr(ParseExpression(), [](Expr *E) { return E->hasPlaceholderType() ? ExprError() : E; @@ -2897,9 +2898,8 @@ ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, assert(Tok.isOneOf(tok::equal, tok::l_brace) && "Data member initializer not starting with '=' or '{'"); - EnterExpressionEvaluationContext Context(Actions, - Sema::PotentiallyEvaluated, - D); + EnterExpressionEvaluationContext Context( + Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, D); if (TryConsumeToken(tok::equal, EqualLoc)) { if (Tok.is(tok::kw_delete)) { // In principle, an initializer of '= delete p;' is legal, but it will diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index ed7b8f33fc..6a81da753b 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -198,8 +198,8 @@ ExprResult Parser::ParseConstantExpression(TypeCastState isTypeCast) { // An expression is potentially evaluated unless it appears where an // integral constant expression is required (see 5.19) [...]. // C++98 and C++11 have no such rule, but this is only a defect in C++98. - EnterExpressionEvaluationContext ConstantEvaluated(Actions, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult LHS(ParseCastExpression(false, false, isTypeCast)); ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); @@ -1313,7 +1313,8 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, // C++11 [expr.unary.noexcept]p1: // The noexcept operator determines whether the evaluation of its operand, // which is an unevaluated operand, can throw an exception. - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated); ExprResult Result = ParseExpression(); T.consumeClose(); @@ -1882,9 +1883,10 @@ ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { if (!Name) return ExprError(); - - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); return Actions.ActOnSizeofParameterPackExpr(getCurScope(), OpTok.getLocation(), @@ -1895,8 +1897,9 @@ ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof)) Diag(OpTok, diag::warn_cxx98_compat_alignof); - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); bool isCastExpr; ParsedType CastTy; @@ -2569,7 +2572,8 @@ ExprResult Parser::ParseGenericSelectionExpression() { { // C11 6.5.1.1p3 "The controlling expression of a generic selection is // not evaluated." - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated); ControllingExpr = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); if (ControllingExpr.isInvalid()) { diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index b549f60ce0..671a815911 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -866,8 +866,8 @@ Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, // Each lambda init-capture forms its own full expression, which clears // Actions.MaybeODRUseExprs. So create an expression evaluation context // to save the necessary state, and restore it later. - EnterExpressionEvaluationContext EC(Actions, - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext EC( + Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); if (TryConsumeToken(tok::equal)) InitKind = LambdaCaptureInitKind::CopyInit; @@ -1405,8 +1405,9 @@ ExprResult Parser::ParseCXXTypeid() { // We enter the unevaluated context before trying to determine whether we // have a type-id, because the tentative parse logic will try to resolve // names, and must treat them as unevaluated. - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); if (isTypeIdInParens()) { TypeResult Ty = ParseTypeName(); @@ -1469,7 +1470,8 @@ ExprResult Parser::ParseCXXUuidof() { Ty.get().getAsOpaquePtr(), T.getCloseLocation()); } else { - EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + Actions, Sema::ExpressionEvaluationContext::Unevaluated); Result = ParseExpression(); // Match the ')'. diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 05c22b04d8..94f0dadd16 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1179,7 +1179,8 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) { StmtResult ThenStmt; { EnterExpressionEvaluationContext PotentiallyDiscarded( - Actions, Sema::DiscardedStatement, nullptr, false, + Actions, Sema::ExpressionEvaluationContext::DiscardedStatement, nullptr, + false, /*ShouldEnter=*/ConstexprCondition && !*ConstexprCondition); ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc); } @@ -1212,7 +1213,8 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) { Tok.is(tok::l_brace)); EnterExpressionEvaluationContext PotentiallyDiscarded( - Actions, Sema::DiscardedStatement, nullptr, false, + Actions, Sema::ExpressionEvaluationContext::DiscardedStatement, nullptr, + false, /*ShouldEnter=*/ConstexprCondition && *ConstexprCondition); ElseStmt = ParseStatement(); diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 428ff38829..d2b18e7c0a 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -701,8 +701,8 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { // end of the template-parameter-list rather than a greater-than // operator. GreaterThanIsOperatorScope G(GreaterThanIsOperator, false); - EnterExpressionEvaluationContext ConstantEvaluated(Actions, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); if (DefaultArg.isInvalid()) @@ -1275,7 +1275,8 @@ bool Parser::IsTemplateArgumentList(unsigned Skip) { bool Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs) { // Template argument lists are constant-evaluation contexts. - EnterExpressionEvaluationContext EvalContext(Actions,Sema::ConstantEvaluated); + EnterExpressionEvaluationContext EvalContext( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); ColonProtectionRAIIObject ColonProtection(*this, false); do { diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 057e43f211..294b56059b 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -122,8 +122,9 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, // Tell diagnostics how to render things from the AST library. Diags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument, &Context); - ExprEvalContexts.emplace_back(PotentiallyEvaluated, 0, CleanupInfo{}, nullptr, - false); + ExprEvalContexts.emplace_back( + ExpressionEvaluationContext::PotentiallyEvaluated, 0, CleanupInfo{}, + nullptr, false); FunctionScopes.push_back(new FunctionScopeInfo(Diags)); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 9665fe09f6..40fd2bd66d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -10850,7 +10850,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { // Regardless, we don't want to ignore array nesting when // constructing this copy. if (type->isStructureOrClassType()) { - EnterExpressionEvaluationContext scope(*this, PotentiallyEvaluated); + EnterExpressionEvaluationContext scope( + *this, ExpressionEvaluationContext::PotentiallyEvaluated); SourceLocation poi = var->getLocation(); Expr *varRef =new (Context) DeclRefExpr(var, false, type, VK_LValue, poi); ExprResult result diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 508cb840a0..fd3f266c9a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -981,7 +981,8 @@ namespace { enum class IsTupleLike { TupleLike, NotTupleLike, Error }; } static IsTupleLike isTupleLike(Sema &S, SourceLocation Loc, QualType T, llvm::APSInt &Size) { - EnterExpressionEvaluationContext ContextRAII(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext ContextRAII( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); DeclarationName Value = S.PP.getIdentifierInfo("value"); LookupResult R(S, Value, Loc, Sema::LookupOrdinaryName); @@ -13117,7 +13118,8 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, if (!Invalid && !ExDeclType->isDependentType()) { if (const RecordType *recordType = ExDeclType->getAs()) { // Insulate this from anything else we might currently be parsing. - EnterExpressionEvaluationContext scope(*this, PotentiallyEvaluated); + EnterExpressionEvaluationContext scope( + *this, ExpressionEvaluationContext::PotentiallyEvaluated); // C++ [except.handle]p16: // The object declared in an exception-declaration or, if the @@ -14201,7 +14203,8 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, Decl *D) { // new expression evaluation context that is associated with this static // data member. if (isStaticDataMember(D)) - PushExpressionEvaluationContext(PotentiallyEvaluated, D); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated, D); } /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0cc2d35fc1..454bc32d88 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1431,7 +1431,8 @@ Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc, // Decay and strip qualifiers for the controlling expression type, and handle // placeholder type replacement. See committee discussion from WG14 DR423. { - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); ExprResult R = DefaultFunctionArrayLvalueConversion(ControllingExpr); if (R.isInvalid()) return ExprError(); @@ -4555,8 +4556,8 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, if (Param->hasUninstantiatedDefaultArg()) { Expr *UninstExpr = Param->getUninstantiatedDefaultArg(); - EnterExpressionEvaluationContext EvalContext(*this, PotentiallyEvaluated, - Param); + EnterExpressionEvaluationContext EvalContext( + *this, ExpressionEvaluationContext::PotentiallyEvaluated, Param); // Instantiate the expression. MultiLevelTemplateArgumentList MutiLevelArgList @@ -12250,7 +12251,8 @@ void Sema::ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope) { // Enter a new evaluation context to insulate the block from any // cleanups from the enclosing full-expression. - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); } void Sema::ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, @@ -13143,7 +13145,7 @@ void Sema::PopExpressionEvaluationContext() { unsigned NumTypos = Rec.NumTypos; if (!Rec.Lambdas.empty()) { - if (Rec.isUnevaluated() || Rec.Context == ConstantEvaluated) { + if (Rec.isUnevaluated() || Rec.isConstantEvaluated()) { unsigned D; if (Rec.isUnevaluated()) { // C++11 [expr.prim.lambda]p2: @@ -13164,7 +13166,7 @@ void Sema::PopExpressionEvaluationContext() { // are part of function-signatures. Be mindful that P0315 (Lambdas in // unevaluated contexts) might lift some of these restrictions in a // future version. - if (Rec.Context != ConstantEvaluated || !getLangOpts().CPlusPlus1z) + if (!Rec.isConstantEvaluated() || !getLangOpts().CPlusPlus1z) for (const auto *L : Rec.Lambdas) Diag(L->getLocStart(), D); } else { @@ -13181,7 +13183,7 @@ void Sema::PopExpressionEvaluationContext() { // temporaries that we may have created as part of the evaluation of // the expression in that context: they aren't relevant because they // will never be constructed. - if (Rec.isUnevaluated() || Rec.Context == ConstantEvaluated) { + if (Rec.isUnevaluated() || Rec.isConstantEvaluated()) { ExprCleanupObjects.erase(ExprCleanupObjects.begin() + Rec.NumCleanupObjects, ExprCleanupObjects.end()); Cleanup = Rec.ParentCleanup; @@ -13223,19 +13225,19 @@ ExprResult Sema::HandleExprEvaluationContextForTypeof(Expr *E) { /// captured by C++'s idea of an "unevaluated context". static bool isEvaluatableContext(Sema &SemaRef) { switch (SemaRef.ExprEvalContexts.back().Context) { - case Sema::Unevaluated: - case Sema::UnevaluatedAbstract: - case Sema::DiscardedStatement: + case Sema::ExpressionEvaluationContext::Unevaluated: + case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: + case Sema::ExpressionEvaluationContext::DiscardedStatement: // Expressions in this context are never evaluated. return false; - case Sema::UnevaluatedList: - case Sema::ConstantEvaluated: - case Sema::PotentiallyEvaluated: + case Sema::ExpressionEvaluationContext::UnevaluatedList: + case Sema::ExpressionEvaluationContext::ConstantEvaluated: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: // Expressions in this context could be evaluated. return true; - case Sema::PotentiallyEvaluatedIfUsed: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: // Referenced declarations will only be used if the construct in the // containing expression is used, at which point we'll be given another // turn to mark them. @@ -13253,17 +13255,17 @@ static bool isOdrUseContext(Sema &SemaRef, bool SkipDependentUses = true) { return false; switch (SemaRef.ExprEvalContexts.back().Context) { - case Sema::Unevaluated: - case Sema::UnevaluatedList: - case Sema::UnevaluatedAbstract: - case Sema::DiscardedStatement: + case Sema::ExpressionEvaluationContext::Unevaluated: + case Sema::ExpressionEvaluationContext::UnevaluatedList: + case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: + case Sema::ExpressionEvaluationContext::DiscardedStatement: return false; - case Sema::ConstantEvaluated: - case Sema::PotentiallyEvaluated: + case Sema::ExpressionEvaluationContext::ConstantEvaluated: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: return true; - case Sema::PotentiallyEvaluatedIfUsed: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: return false; } llvm_unreachable("Invalid context"); @@ -13718,7 +13720,8 @@ static bool captureInBlock(BlockScopeInfo *BSI, VarDecl *Var, // Enter a new evaluation context to insulate the copy // full-expression. - EnterExpressionEvaluationContext scope(S, S.PotentiallyEvaluated); + EnterExpressionEvaluationContext scope( + S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); // According to the blocks spec, the capture of a variable from // the stack requires a const copy constructor. This is not true @@ -14469,7 +14472,8 @@ bool MarkReferencedDecls::TraverseTemplateArgument( const TemplateArgument &Arg) { { // A non-type template argument is a constant-evaluated context. - EnterExpressionEvaluationContext Evaluated(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Evaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); if (Arg.getKind() == TemplateArgument::Declaration) { if (Decl *D = Arg.getAsDecl()) S.MarkAnyDeclReferenced(Loc, D, true); @@ -14589,19 +14593,19 @@ void Sema::MarkDeclarationsReferencedInExpr(Expr *E, bool Sema::DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, const PartialDiagnostic &PD) { switch (ExprEvalContexts.back().Context) { - case Unevaluated: - case UnevaluatedList: - case UnevaluatedAbstract: - case DiscardedStatement: + case ExpressionEvaluationContext::Unevaluated: + case ExpressionEvaluationContext::UnevaluatedList: + case ExpressionEvaluationContext::UnevaluatedAbstract: + case ExpressionEvaluationContext::DiscardedStatement: // The argument will never be evaluated, so don't complain. break; - case ConstantEvaluated: + case ExpressionEvaluationContext::ConstantEvaluated: // Relevant diagnostics should be produced by constant evaluation. break; - case PotentiallyEvaluated: - case PotentiallyEvaluatedIfUsed: + case ExpressionEvaluationContext::PotentiallyEvaluated: + case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: if (Statement && getCurFunctionOrMethodDecl()) { FunctionScopes.back()->PossiblyUnreachableDiags. push_back(sema::PossiblyUnreachableDiag(PD, Loc, Statement)); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 174f750ab6..85ff3a1e08 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4589,7 +4589,8 @@ static bool evaluateTypeTrait(Sema &S, TypeTrait Kind, SourceLocation KWLoc, // Perform the initialization in an unevaluated context within a SFINAE // trap at translation unit scope. - EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl()); InitializedEntity To(InitializedEntity::InitializeTemporary(Args[0])); @@ -4765,7 +4766,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT, // Perform the initialization in an unevaluated context within a SFINAE // trap at translation unit scope. - EnterExpressionEvaluationContext Unevaluated(Self, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); InitializationSequence Init(Self, To, Kind, FromPtr); @@ -4816,7 +4818,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT, // Attempt the assignment in an unevaluated context within a SFINAE // trap at translation unit scope. - EnterExpressionEvaluationContext Unevaluated(Self, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); ExprResult Result = Self.BuildBinOp(/*S=*/nullptr, KeyLoc, BO_Assign, &Lhs, @@ -6726,7 +6729,8 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl, // follows the normal lifetime rules for block literals instead of being // autoreleased. DiagnosticErrorTrap Trap(Diags); - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); ExprResult Exp = BuildBlockForLambdaConversion(E->getExprLoc(), E->getExprLoc(), Method, E); diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp index 66f346eb3b..b18de7e946 100644 --- a/lib/Sema/SemaExprMember.cpp +++ b/lib/Sema/SemaExprMember.cpp @@ -133,20 +133,20 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, IMAKind AbstractInstanceResult = IMA_Static; // happens to be 'false' assert(!AbstractInstanceResult); switch (SemaRef.ExprEvalContexts.back().Context) { - case Sema::Unevaluated: - case Sema::UnevaluatedList: + case Sema::ExpressionEvaluationContext::Unevaluated: + case Sema::ExpressionEvaluationContext::UnevaluatedList: if (isField && SemaRef.getLangOpts().CPlusPlus11) AbstractInstanceResult = IMA_Field_Uneval_Context; break; - case Sema::UnevaluatedAbstract: + case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: AbstractInstanceResult = IMA_Abstract; break; - case Sema::DiscardedStatement: - case Sema::ConstantEvaluated: - case Sema::PotentiallyEvaluated: - case Sema::PotentiallyEvaluatedIfUsed: + case Sema::ExpressionEvaluationContext::DiscardedStatement: + case Sema::ExpressionEvaluationContext::ConstantEvaluated: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: break; } diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index 782a35e56d..2b13f2af68 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -1127,7 +1127,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, // Enter a new evaluation context to insulate the lambda from any // cleanups from the enclosing full-expression. - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); } void Sema::ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, @@ -1605,9 +1606,9 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, // C++11 [expr.prim.lambda]p2: // A lambda-expression shall not appear in an unevaluated operand // (Clause 5). - case Unevaluated: - case UnevaluatedList: - case UnevaluatedAbstract: + case ExpressionEvaluationContext::Unevaluated: + case ExpressionEvaluationContext::UnevaluatedList: + case ExpressionEvaluationContext::UnevaluatedAbstract: // C++1y [expr.const]p2: // A conditional-expression e is a core constant expression unless the // evaluation of e, following the rules of the abstract machine, would @@ -1617,16 +1618,16 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, // where this should be allowed. We should probably fix this when DR1607 is // ratified, it lays out the exact set of conditions where we shouldn't // allow a lambda-expression. - case ConstantEvaluated: + case ExpressionEvaluationContext::ConstantEvaluated: // We don't actually diagnose this case immediately, because we // could be within a context where we might find out later that // the expression is potentially evaluated (e.g., for typeid). ExprEvalContexts.back().Lambdas.push_back(Lambda); break; - case DiscardedStatement: - case PotentiallyEvaluated: - case PotentiallyEvaluatedIfUsed: + case ExpressionEvaluationContext::DiscardedStatement: + case ExpressionEvaluationContext::PotentiallyEvaluated: + case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: break; } } diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 7d47997455..616ab05eae 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -1050,7 +1050,8 @@ void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, Scope *CurScope, SourceLocation Loc) { DSAStack->push(DKind, DirName, CurScope, Loc); - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); } void Sema::StartOpenMPClause(OpenMPClauseKind K) { @@ -10907,7 +10908,8 @@ void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { else CurContext = DRD; - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); QualType ReductionType = DRD->getType(); // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will @@ -10961,7 +10963,8 @@ void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { else CurContext = DRD; - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); QualType ReductionType = DRD->getType(); // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index bba8216fa2..e0680e7469 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -5888,7 +5888,8 @@ Sema::AddOverloadCandidate(FunctionDecl *Function, return; // Overload resolution is always an unevaluated context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); // Add this candidate OverloadCandidate &Candidate = @@ -6411,7 +6412,8 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, return; // Overload resolution is always an unevaluated context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); // Add this candidate OverloadCandidate &Candidate = @@ -6667,7 +6669,8 @@ bool Sema::CheckNonDependentConversions( CandidateSet.allocateConversionSequences(ThisConversions + Args.size()); // Overload resolution is always an unevaluated context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); // For a method call, check the 'this' conversion here too. DR1391 doesn't // require that, but this check should never result in a hard error, and @@ -6775,7 +6778,8 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, return; // Overload resolution is always an unevaluated context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); // Add this candidate OverloadCandidate &Candidate = CandidateSet.addCandidate(1); @@ -6966,7 +6970,8 @@ void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, return; // Overload resolution is always an unevaluated context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); OverloadCandidate &Candidate = CandidateSet.addCandidate(Args.size() + 1); Candidate.FoundDecl = FoundDecl; @@ -7124,7 +7129,8 @@ void Sema::AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, bool IsAssignmentOperator, unsigned NumContextualBoolArguments) { // Overload resolution is always an unevaluated context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); // Add this candidate OverloadCandidate &Candidate = CandidateSet.addCandidate(Args.size()); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 4cf1ad9e1c..9be1c56f06 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2877,7 +2877,8 @@ Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { bool HasDeducedReturnType = CurLambda && hasDeducedReturnType(CurLambda->CallOperator); - if (ExprEvalContexts.back().Context == DiscardedStatement && + if (ExprEvalContexts.back().Context == + ExpressionEvaluationContext::DiscardedStatement && (HasDeducedReturnType || CurCap->HasImplicitReturnType)) { if (RetValExp) { ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc); @@ -3169,7 +3170,8 @@ StmtResult Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope) { StmtResult R = BuildReturnStmt(ReturnLoc, RetValExp); - if (R.isInvalid() || ExprEvalContexts.back().Context == DiscardedStatement) + if (R.isInvalid() || ExprEvalContexts.back().Context == + ExpressionEvaluationContext::DiscardedStatement) return R; if (VarDecl *VD = @@ -3225,7 +3227,8 @@ StmtResult Sema::BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { // C++1z: discarded return statements are not considered when deducing a // return type. - if (ExprEvalContexts.back().Context == DiscardedStatement && + if (ExprEvalContexts.back().Context == + ExpressionEvaluationContext::DiscardedStatement && FnRetType->getContainedAutoType()) { if (RetValExp) { ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc); @@ -3925,7 +3928,8 @@ void Sema::ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, else CurContext = CD; - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); } void Sema::ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, @@ -3977,7 +3981,8 @@ void Sema::ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, else CurContext = CD; - PushExpressionEvaluationContext(PotentiallyEvaluated); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::PotentiallyEvaluated); } void Sema::ActOnCapturedRegionError() { diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index 76de9e2993..5f91cac14a 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -623,8 +623,9 @@ ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS, Info.clear(); if (IsUnevaluatedContext) - PushExpressionEvaluationContext(UnevaluatedAbstract, - ReuseLambdaContextDecl); + PushExpressionEvaluationContext( + ExpressionEvaluationContext::UnevaluatedAbstract, + ReuseLambdaContextDecl); ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id, /*trailing lparen*/ false, diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 0797bde2bc..73a6854161 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4054,8 +4054,8 @@ SubstDefaultTemplateArgument(Sema &SemaRef, for (unsigned i = 0, e = Param->getDepth(); i != e; ++i) TemplateArgLists.addOuterTemplateArguments(None); - EnterExpressionEvaluationContext ConstantEvaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext ConstantEvaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); return SemaRef.SubstExpr(Param->getDefaultArgument(), TemplateArgLists); } @@ -5753,8 +5753,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // The initialization of the parameter from the argument is // a constant-evaluated context. - EnterExpressionEvaluationContext ConstantEvaluated(*this, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext ConstantEvaluated( + *this, Sema::ExpressionEvaluationContext::ConstantEvaluated); if (getLangOpts().CPlusPlus1z) { // C++1z [temp.arg.nontype]p1: diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 4116ae979b..ebdf6dd57f 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -2447,7 +2447,8 @@ FinishTemplateArgumentDeduction( SmallVectorImpl &Deduced, TemplateDeductionInfo &Info) { // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap Trap(S); Sema::ContextRAII SavedContext(S, getAsDeclContextOrEnclosing(Partial)); @@ -2525,7 +2526,8 @@ static Sema::TemplateDeductionResult FinishTemplateArgumentDeduction( SmallVectorImpl &Deduced, TemplateDeductionInfo &Info) { // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap Trap(S); Sema::ContextRAII SavedContext(S, getAsDeclContextOrEnclosing(Template)); @@ -2575,7 +2577,8 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, // list (14.8.2). // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); SFINAETrap Trap(*this); SmallVector Deduced; @@ -2617,7 +2620,8 @@ Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, // list (14.8.2). // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); SFINAETrap Trap(*this); SmallVector Deduced; @@ -2697,7 +2701,8 @@ Sema::SubstituteExplicitTemplateArguments( } // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); SFINAETrap Trap(*this); // C++ [temp.arg.explicit]p3: @@ -2995,7 +3000,8 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( SmallVectorImpl const *OriginalCallArgs, bool PartialOverloading, llvm::function_ref CheckNonDependent) { // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); SFINAETrap Trap(*this); // Enter a new template instantiation context while we instantiate the @@ -3731,7 +3737,8 @@ Sema::TemplateDeductionResult Sema::DeduceTemplateArguments( } // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); SFINAETrap Trap(*this); Deduced.resize(TemplateParams->size()); @@ -3979,7 +3986,8 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *ConversionTemplate, } // Unevaluated SFINAE context. - EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + *this, Sema::ExpressionEvaluationContext::Unevaluated); SFINAETrap Trap(*this); // C++ [temp.deduct.conv]p1: diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 67e330a6da..edd6edfce9 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -2002,8 +2002,8 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. ContextRAII SavedContext(*this, Instantiation); - EnterExpressionEvaluationContext EvalContext(*this, - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext EvalContext( + *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); // If this is an instantiation of a local class, merge this local // instantiation scope with the enclosing scope. Otherwise, every @@ -2233,8 +2233,8 @@ bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation, // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. ContextRAII SavedContext(*this, Instantiation); - EnterExpressionEvaluationContext EvalContext(*this, - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext EvalContext( + *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true); @@ -2305,8 +2305,8 @@ bool Sema::InstantiateInClassInitializer( // Enter the scope of this instantiation. We don't use PushDeclContext because // we don't have a scope. ContextRAII SavedContext(*this, Instantiation->getParent()); - EnterExpressionEvaluationContext EvalContext(*this, - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext EvalContext( + *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); LocalInstantiationScope Scope(*this, true); diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 1482aa606b..9a71a17561 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -81,7 +81,8 @@ static void instantiateDependentAlignedAttr( const AlignedAttr *Aligned, Decl *New, bool IsPackExpansion) { if (Aligned->isAlignmentExpr()) { // The alignment expression is a constant expression. - EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Result = S.SubstExpr(Aligned->getAlignmentExpr(), TemplateArgs); if (!Result.isInvalid()) S.AddAlignedAttr(Aligned->getLocation(), New, Result.getAs(), @@ -138,7 +139,8 @@ static void instantiateDependentAssumeAlignedAttr( Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AssumeAlignedAttr *Aligned, Decl *New) { // The alignment expression is a constant expression. - EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); Expr *E, *OE = nullptr; ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs); @@ -161,7 +163,8 @@ static void instantiateDependentAlignValueAttr( Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AlignValueAttr *Aligned, Decl *New) { // The alignment expression is a constant expression. - EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs); if (!Result.isInvalid()) S.AddAlignValueAttr(Aligned->getLocation(), New, Result.getAs(), @@ -184,7 +187,8 @@ static Expr *instantiateDependentFunctionAttrCondition( Expr *Cond = nullptr; { Sema::ContextRAII SwitchContext(S, New); - EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Result = S.SubstExpr(OldCond, TemplateArgs); if (Result.isInvalid()) return nullptr; @@ -239,7 +243,8 @@ static void instantiateDependentCUDALaunchBoundsAttr( Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const CUDALaunchBoundsAttr &Attr, Decl *New) { // The alignment expression is a constant expression. - EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Result = S.SubstExpr(Attr.getMaxThreads(), TemplateArgs); if (Result.isInvalid()) @@ -790,8 +795,8 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { BitWidth = nullptr; else if (BitWidth) { // The bit-width expression is a constant expression. - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult InstantiatedBitWidth = SemaRef.SubstExpr(BitWidth, TemplateArgs); @@ -967,8 +972,8 @@ Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { Expr *AssertExpr = D->getAssertExpr(); // The expression in a static assertion is a constant expression. - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult InstantiatedAssertExpr = SemaRef.SubstExpr(AssertExpr, TemplateArgs); @@ -1078,8 +1083,8 @@ void TemplateDeclInstantiator::InstantiateEnumDefinition( ExprResult Value((Expr *)nullptr); if (Expr *UninstValue = EC->getInitExpr()) { // The enumerator's value expression is a constant expression. - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); Value = SemaRef.SubstExpr(UninstValue, TemplateArgs); } @@ -2274,8 +2279,8 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( Param->setInvalidDecl(); if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { - EnterExpressionEvaluationContext ConstantEvaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext ConstantEvaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Value = SemaRef.SubstExpr(D->getDefaultArgument(), TemplateArgs); if (!Value.isInvalid()) Param->setDefaultArgument(Value.get()); @@ -3851,8 +3856,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // Copy the inner loc start from the pattern. Function->setInnerLocStart(PatternDecl->getInnerLocStart()); - EnterExpressionEvaluationContext EvalContext(*this, - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext EvalContext( + *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); // Introduce a new scope where local variable instantiations will be // recorded, unless we're actually a member function within a local @@ -4116,9 +4121,11 @@ void Sema::InstantiateVariableInitializer( if (OldVar->getInit()) { if (Var->isStaticDataMember() && !OldVar->isOutOfLine()) - PushExpressionEvaluationContext(Sema::ConstantEvaluated, OldVar); + PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::ConstantEvaluated, OldVar); else - PushExpressionEvaluationContext(Sema::PotentiallyEvaluated, OldVar); + PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::PotentiallyEvaluated, OldVar); // Instantiate the initializer. ExprResult Init; diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 1203150112..5181fbaa58 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -3867,7 +3867,9 @@ bool TreeTransform::TransformTemplateArgument( case TemplateArgument::Expression: { // Template argument expressions are constant expressions. EnterExpressionEvaluationContext Unevaluated( - getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated); + getSema(), Uneval + ? Sema::ExpressionEvaluationContext::Unevaluated + : Sema::ExpressionEvaluationContext::ConstantEvaluated); Expr *InputExpr = Input.getSourceExpression(); if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); @@ -4572,8 +4574,8 @@ TreeTransform::TransformConstantArrayType(TypeLocBuilder &TLB, Expr *Size = TL.getSizeExpr(); if (Size) { - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); Size = getDerived().TransformExpr(Size).template getAs(); Size = SemaRef.ActOnConstantExpression(Size).get(); } @@ -4621,8 +4623,8 @@ TreeTransform::TransformVariableArrayType(TypeLocBuilder &TLB, ExprResult SizeResult; { - EnterExpressionEvaluationContext Context(SemaRef, - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext Context( + SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); SizeResult = getDerived().TransformExpr(T->getSizeExpr()); } if (SizeResult.isInvalid()) @@ -4666,8 +4668,8 @@ TreeTransform::TransformDependentSizedArrayType(TypeLocBuilder &TLB, return QualType(); // Array bounds are constant expressions. - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); // Prefer the expression from the TypeLoc; the other may have been uniqued. Expr *origSize = TL.getSizeExpr(); @@ -4716,8 +4718,8 @@ QualType TreeTransform::TransformDependentSizedExtVectorType( return QualType(); // Vector sizes are constant expressions. - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); Size = SemaRef.ActOnConstantExpression(Size); @@ -5184,8 +5186,8 @@ bool TreeTransform::TransformExceptionSpec( // Instantiate a dynamic noexcept expression, if any. if (ESI.Type == EST_ComputedNoexcept) { - EnterExpressionEvaluationContext Unevaluated(getSema(), - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); if (NoexceptExpr.isInvalid()) return true; @@ -5352,8 +5354,9 @@ template QualType TreeTransform::TransformTypeOfExprType(TypeLocBuilder &TLB, TypeOfExprTypeLoc TL) { // typeof expressions are not potentially evaluated contexts - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); if (E.isInvalid()) @@ -5410,8 +5413,9 @@ QualType TreeTransform::TransformDecltypeType(TypeLocBuilder &TLB, const DecltypeType *T = TL.getTypePtr(); // decltype expressions are not potentially evaluated contexts - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, - nullptr, /*IsDecltype=*/ true); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, + /*IsDecltype=*/true); ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); if (E.isInvalid()) @@ -6386,8 +6390,8 @@ StmtResult TreeTransform::TransformCaseStmt(CaseStmt *S) { ExprResult LHS, RHS; { - EnterExpressionEvaluationContext Unevaluated(SemaRef, - Sema::ConstantEvaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); // Transform the left-hand case value. LHS = getDerived().TransformExpr(S->getLHS()); @@ -8933,8 +8937,9 @@ TreeTransform::TransformUnaryExprOrTypeTraitExpr( // C++0x [expr.sizeof]p1: // The operand is either an expression, which is an unevaluated operand // [...] - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); // Try to recover if we have something like sizeof(T::X) where X is a type. // Notably, there must be *exactly* one set of parens if X is a type. @@ -9770,8 +9775,9 @@ TreeTransform::TransformCXXTypeidExpr(CXXTypeidExpr *E) { // after we perform semantic analysis. We speculatively assume it is // unevaluated; it will get fixed later if the subexpression is in fact // potentially evaluated. - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, - Sema::ReuseLambdaContextDecl); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, + Sema::ReuseLambdaContextDecl); ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); if (SubExpr.isInvalid()) @@ -9806,7 +9812,8 @@ TreeTransform::TransformCXXUuidofExpr(CXXUuidofExpr *E) { E->getLocEnd()); } - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); if (SubExpr.isInvalid()) @@ -10420,7 +10427,8 @@ TreeTransform::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { ExprResult SubExpr; { - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); if (SubExpr.isInvalid()) return ExprError(); @@ -10441,7 +10449,8 @@ ExprResult TreeTransform::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { ExprResult SubExpr; { - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); if (SubExpr.isInvalid()) return ExprError(); @@ -10677,8 +10686,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr *E) { C != CEnd; ++C) { if (!E->isInitCapture(C)) continue; - EnterExpressionEvaluationContext EEEC(getSema(), - Sema::PotentiallyEvaluated); + EnterExpressionEvaluationContext EEEC( + getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated); ExprResult NewExprInitResult = getDerived().TransformInitializer( C->getCapturedVar()->getInit(), C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); @@ -10754,7 +10763,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr *E) { auto *P = NewCallOperator->getParamDecl(I); if (P->hasUninstantiatedDefaultArg()) { EnterExpressionEvaluationContext Eval( - getSema(), Sema::PotentiallyEvaluatedIfUsed, P); + getSema(), + Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P); ExprResult R = getDerived().TransformExpr( E->getCallOperator()->getParamDecl(I)->getDefaultArg()); P->setDefaultArg(R.get()); @@ -10894,7 +10904,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr *E) { // Enter a new evaluation context to insulate the lambda from any // cleanups from the enclosing full-expression. - getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); + getSema().PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::PotentiallyEvaluated); // Instantiate the body of the lambda expression. StmtResult Body = @@ -11130,7 +11141,8 @@ TreeTransform::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) template ExprResult TreeTransform::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { - EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); if (SubExpr.isInvalid()) return ExprError(); @@ -11163,7 +11175,8 @@ TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) { if (!E->isValueDependent()) return E; - EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated); + EnterExpressionEvaluationContext Unevaluated( + getSema(), Sema::ExpressionEvaluationContext::Unevaluated); ArrayRef PackArgs; TemplateArgument ArgStorage; diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index c516b53101..8aaa28beaa 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -1036,7 +1036,7 @@ namespace { OS << " " << getType() << " tempInst" << getUpperName() << ";\n"; OS << " {\n"; OS << " EnterExpressionEvaluationContext " - << "Unevaluated(S, Sema::Unevaluated);\n"; + << "Unevaluated(S, Sema::ExpressionEvaluationContext::Unevaluated);\n"; OS << " ExprResult " << "Result = S.SubstExpr(" << "A->get" << getUpperName() << "(), TemplateArgs);\n"; OS << " tempInst" << getUpperName() << " = " @@ -1083,7 +1083,7 @@ namespace { << "[A->" << getLowerName() << "_size()];\n"; OS << " {\n"; OS << " EnterExpressionEvaluationContext " - << "Unevaluated(S, Sema::Unevaluated);\n"; + << "Unevaluated(S, Sema::ExpressionEvaluationContext::Unevaluated);\n"; OS << " " << getType() << " *TI = tempInst" << getUpperName() << ";\n"; OS << " " << getType() << " *I = A->" << getLowerName()