From ccb97f52afeb4ce5b239a6f3b44956d9e220e5e3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 21 May 2009 21:38:12 +0000 Subject: [PATCH] Template instantiation for initializer lists git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72229 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateExpr.cpp | 16 +++++++++++++- test/SemaTemplate/instantiate-expr-4.cpp | 28 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index 8cd60edb67..283b0d35a2 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -60,7 +60,7 @@ namespace { OwningExprResult VisitShuffleVectorExpr(ShuffleVectorExpr *E); OwningExprResult VisitChooseExpr(ChooseExpr *E); OwningExprResult VisitVAArgExpr(VAArgExpr *E); - // FIXME: InitListExpr + OwningExprResult VisitInitListExpr(InitListExpr *E); // FIXME: DesignatedInitExpr // FIXME: ImplicitValueInitExpr // FIXME: ExtVectorElementExpr @@ -580,6 +580,20 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitVAArgExpr(VAArgExpr *E) { T.getAsOpaquePtr(), E->getRParenLoc()); } +Sema::OwningExprResult +TemplateExprInstantiator::VisitInitListExpr(InitListExpr *E) { + ExprVector Inits(SemaRef); + for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { + OwningExprResult Init = Visit(E->getInit(I)); + if (Init.isInvalid()) + return SemaRef.ExprError(); + Inits.push_back(Init.takeAs()); + } + + return SemaRef.ActOnInitList(E->getLBraceLoc(), move_arg(Inits), + E->getRBraceLoc()); +} + Sema::OwningExprResult TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { bool isSizeOf = E->isSizeOf(); diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index 5c32d8c197..09d574176a 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -150,3 +150,31 @@ struct is_pod { static const int is_pod0[is_pod::value? -1 : 1]; static const int is_pod1[is_pod::value? 1 : -1]; + +// --------------------------------------------------------------------- +// initializer lists +// --------------------------------------------------------------------- +template +struct InitList1 { + void f(Val1 val1) { + T x = { val1 }; + } +}; + +struct APair { + int *x; + const float *y; +}; + +template struct InitList1; +template struct InitList1; + +template +struct InitList2 { + void f(Val1 val1, Val2 val2) { + T x = { val1, val2 }; // expected-error{{incompatible}} + } +}; + +template struct InitList2; +template struct InitList2; // expected-note{{instantiation}} -- 2.40.0