@@ -28,13 +28,33 @@ using namespace sema;
2828CXXExpansionStmtDecl *
2929Sema::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
3448CXXExpansionStmtDecl *
3549Sema::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
4060ExprResult 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
5576StmtResult 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