Skip to content

Commit 6ea2433

Browse files
committed
Add Sema for CXXExpansionStmtDecl
1 parent a3baa3f commit 6ea2433

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def select_constexpr_spec_kind : TextSubstitution<
2222
def fatal_too_many_errors
2323
: Error<"too many errors emitted, stopping now">, DefaultFatal;
2424

25+
// TODO: Remove this.
26+
def err_expansion_statements_todo : Error<
27+
"TODO (expansion statements)">;
28+
2529
def warn_stack_exhausted : Warning<
2630
"stack nearly exhausted; compilation time may suffer, and "
2731
"crashes due to stack overflow are likely">,

clang/lib/Sema/SemaExpand.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,33 @@ using namespace sema;
2828
CXXExpansionStmtDecl *
2929
Sema::ActOnCXXExpansionStmtDecl(unsigned TemplateDepth,
3030
SourceLocation TemplateKWLoc) {
31-
llvm_unreachable("TODO");
31+
// Create a template parameter '__N'. This will be used to denote the index
32+
// of the element that we're instantiating. CWG 3044 requires this type to
33+
// be 'ptrdiff_t' for iterating expansion statements, so use that in all
34+
// cases.
35+
IdentifierInfo *ParmName = &Context.Idents.get("__N");
36+
QualType ParmTy = Context.getPointerDiffType();
37+
TypeSourceInfo *ParmTI =
38+
Context.getTrivialTypeSourceInfo(ParmTy, TemplateKWLoc);
39+
40+
auto *TParam = NonTypeTemplateParmDecl::Create(
41+
Context, Context.getTranslationUnitDecl(), TemplateKWLoc, TemplateKWLoc,
42+
TemplateDepth, /*Position=*/0, ParmName, ParmTy, /*ParameterPack=*/false,
43+
ParmTI);
44+
45+
return BuildCXXExpansionStmtDecl(CurContext, TemplateKWLoc, TParam);
3246
}
3347

3448
CXXExpansionStmtDecl *
3549
Sema::BuildCXXExpansionStmtDecl(DeclContext *Ctx, SourceLocation TemplateKWLoc,
3650
NonTypeTemplateParmDecl *NTTP) {
37-
llvm_unreachable("TODO");
51+
auto *TParamList = TemplateParameterList::Create(
52+
Context, TemplateKWLoc, TemplateKWLoc, {NTTP}, TemplateKWLoc,
53+
/*RequiresClause=*/nullptr);
54+
auto *Result =
55+
CXXExpansionStmtDecl::Create(Context, Ctx, TemplateKWLoc, TParamList);
56+
Ctx->addDecl(Result);
57+
return Result;
3858
}
3959

4060
ExprResult Sema::ActOnCXXExpansionInitList(MultiExprArg SubExprs,
@@ -49,9 +69,14 @@ StmtResult Sema::ActOnCXXExpansionStmtPattern(
4969
Expr *ExpansionInitializer, SourceLocation LParenLoc,
5070
SourceLocation ColonLoc, SourceLocation RParenLoc,
5171
ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
52-
llvm_unreachable("TODO");
72+
Diag(ColonLoc, diag::err_expansion_stmt_todo);
73+
return StmtError();
5374
}
5475

5576
StmtResult Sema::FinishCXXExpansionStmt(Stmt *Exp, Stmt *Body) {
56-
llvm_unreachable("TODO");
77+
if (!Exp || !Body)
78+
return StmtError();
79+
80+
Diag(Exp->getBeginLoc(), diag::err_expansion_stmt_todo);
81+
return StmtError();
5782
}

0 commit comments

Comments
 (0)