[cfe-commits] r72229 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-expr-4.cpp
Douglas Gregor
dgregor at apple.com
Thu May 21 14:38:15 PDT 2009
Author: dgregor
Date: Thu May 21 16:38:12 2009
New Revision: 72229
URL: http://llvm.org/viewvc/llvm-project?rev=72229&view=rev
Log:
Template instantiation for initializer lists
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72229&r1=72228&r2=72229&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Thu May 21 16:38:12 2009
@@ -60,7 +60,7 @@
OwningExprResult VisitShuffleVectorExpr(ShuffleVectorExpr *E);
OwningExprResult VisitChooseExpr(ChooseExpr *E);
OwningExprResult VisitVAArgExpr(VAArgExpr *E);
- // FIXME: InitListExpr
+ OwningExprResult VisitInitListExpr(InitListExpr *E);
// FIXME: DesignatedInitExpr
// FIXME: ImplicitValueInitExpr
// FIXME: ExtVectorElementExpr
@@ -581,6 +581,20 @@
}
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<Expr>());
+ }
+
+ return SemaRef.ActOnInitList(E->getLBraceLoc(), move_arg(Inits),
+ E->getRBraceLoc());
+}
+
+Sema::OwningExprResult
TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
bool isSizeOf = E->isSizeOf();
Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp?rev=72229&r1=72228&r2=72229&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp Thu May 21 16:38:12 2009
@@ -150,3 +150,31 @@
static const int is_pod0[is_pod<X>::value? -1 : 1];
static const int is_pod1[is_pod<Y>::value? 1 : -1];
+
+// ---------------------------------------------------------------------
+// initializer lists
+// ---------------------------------------------------------------------
+template<typename T, typename Val1>
+struct InitList1 {
+ void f(Val1 val1) {
+ T x = { val1 };
+ }
+};
+
+struct APair {
+ int *x;
+ const float *y;
+};
+
+template struct InitList1<int[1], float>;
+template struct InitList1<APair, int*>;
+
+template<typename T, typename Val1, typename Val2>
+struct InitList2 {
+ void f(Val1 val1, Val2 val2) {
+ T x = { val1, val2 }; // expected-error{{incompatible}}
+ }
+};
+
+template struct InitList2<APair, int*, float*>;
+template struct InitList2<APair, int*, double*>; // expected-note{{instantiation}}
More information about the cfe-commits
mailing list