Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6037,6 +6037,12 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info,
const VarDecl *VD = dyn_cast_or_null<VarDecl>(D);
if (VD && !CheckLocalVariableDeclaration(Info, VD))
return ESR_Failed;

if (const auto *ESD = dyn_cast<CXXExpansionStmtDecl>(D)) {
assert(ESD->getInstantiations() && "not expanded?");
return EvaluateStmt(Result, Info, ESD->getInstantiations(), Case);
}

// Each declaration initialization is its own full-expression.
FullExpressionRAII Scope(Info);
if (!EvaluateDecl(Info, D, /*EvaluateConditionDecl=*/true) &&
Expand Down Expand Up @@ -6309,6 +6315,40 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info,
return Scope.destroy() ? ESR_Succeeded : ESR_Failed;
}

case Stmt::CXXExpansionStmtInstantiationClass: {
BlockScopeRAII Scope(Info);
const auto *Expansion = cast<CXXExpansionStmtInstantiation>(S);
for (const Stmt *Shared : Expansion->getSharedStmts()) {
EvalStmtResult ESR = EvaluateStmt(Result, Info, Shared);
if (ESR != ESR_Succeeded) {
if (ESR != ESR_Failed && !Scope.destroy())
return ESR_Failed;
return ESR;
}
}

// No need to push an extra scope for these since they're already
// CompoundStmts.
EvalStmtResult ESR = ESR_Succeeded;
for (const Stmt *Instantiation : Expansion->getInstantiations()) {
ESR = EvaluateStmt(Result, Info, Instantiation);
if (ESR == ESR_Failed ||
ShouldPropagateBreakContinue(Info, Expansion, &Scope, ESR))
return ESR;
if (ESR != ESR_Continue) {
// Succeeded here actually means we encountered a 'break'.
assert(ESR == ESR_Succeeded || ESR == ESR_Returned);
break;
}
}

// Map Continue back to Succeeded if we fell off the end of the loop.
if (ESR == ESR_Continue)
ESR = ESR_Succeeded;

return Scope.destroy() ? ESR : ESR_Failed;
}

case Stmt::SwitchStmtClass:
return EvaluateSwitch(Result, Info, cast<SwitchStmt>(S));

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,9 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl,
// - using-enum-declaration
continue;

case Decl::CXXExpansionStmt:
continue;

case Decl::Typedef:
case Decl::TypeAlias: {
// - typedef declarations and alias-declarations that do not define
Expand Down
Loading
Loading