aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-21 23:48:18 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-21 23:48:18 +0000
commit690dc7f4f2c0fe87409839b7560c19dee7832195 (patch)
tree74515190a2be1a8e58c700681cbddc7c55a1fb51
parentc4bb7bfe8328f79004517dd268f6146c8066c205 (diff)
Template instantiation for C99 compound literals
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72236 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExpr.cpp5
-rw-r--r--lib/Sema/SemaTemplateInstantiateExpr.cpp22
-rw-r--r--lib/Sema/SemaType.cpp6
-rw-r--r--test/SemaTemplate/instantiate-c99.cpp12
4 files changed, 42 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index e819b1c10f..0d2a2b8a0a 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2719,8 +2719,9 @@ Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
if (literalType->isVariableArrayType())
return ExprError(Diag(LParenLoc, diag::err_variable_object_no_init)
<< SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd()));
- } else if (RequireCompleteType(LParenLoc, literalType,
- diag::err_typecheck_decl_incomplete_type,
+ } else if (!literalType->isDependentType() &&
+ RequireCompleteType(LParenLoc, literalType,
+ diag::err_typecheck_decl_incomplete_type,
SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd())))
return ExprError();
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index 14eef13f8d..fd88b934fb 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -49,7 +49,7 @@ namespace {
OwningExprResult VisitArraySubscriptExpr(ArraySubscriptExpr *E);
OwningExprResult VisitCallExpr(CallExpr *E);
// FIXME: VisitMemberExpr
- // FIXME: CompoundLiteralExpr
+ OwningExprResult VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
OwningExprResult VisitBinaryOperator(BinaryOperator *E);
OwningExprResult VisitCompoundAssignOperator(CompoundAssignOperator *E);
OwningExprResult VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
@@ -289,6 +289,26 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitCallExpr(CallExpr *E) {
}
Sema::OwningExprResult
+TemplateExprInstantiator::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+ SourceLocation FakeTypeLoc
+ = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
+ QualType T = SemaRef.InstantiateType(E->getType(), TemplateArgs,
+ FakeTypeLoc,
+ DeclarationName());
+ if (T.isNull())
+ return SemaRef.ExprError();
+
+ OwningExprResult Init = Visit(E->getInitializer());
+ if (Init.isInvalid())
+ return SemaRef.ExprError();
+
+ return SemaRef.ActOnCompoundLiteral(E->getLParenLoc(),
+ T.getAsOpaquePtr(),
+ /*FIXME*/E->getLParenLoc(),
+ move(Init));
+}
+
+Sema::OwningExprResult
TemplateExprInstantiator::VisitBinaryOperator(BinaryOperator *E) {
Sema::OwningExprResult LHS = Visit(E->getLHS());
if (LHS.isInvalid())
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index e10a912ccf..19ff9bbd4c 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1090,6 +1090,12 @@ void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) {
bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
SourceRange Range1, SourceRange Range2,
QualType PrintType) {
+ // FIXME: Add this assertion to help us flush out problems with
+ // checking for dependent types and type-dependent expressions.
+ //
+ // assert(!T->isDependentType() &&
+ // "Can't ask whether a dependent type is complete");
+
// If we have a complete type, we're done.
if (!T->isIncompleteType())
return false;
diff --git a/test/SemaTemplate/instantiate-c99.cpp b/test/SemaTemplate/instantiate-c99.cpp
index a617594f88..cf691cffad 100644
--- a/test/SemaTemplate/instantiate-c99.cpp
+++ b/test/SemaTemplate/instantiate-c99.cpp
@@ -67,3 +67,15 @@ struct DesigArrayRangeInit0 {
template struct DesigArrayRangeInit0<int[8], 3, 5, float>;
template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// Compound literals
+// ---------------------------------------------------------------------
+template<typename T, typename Arg1, typename Arg2>
+struct CompoundLiteral0 {
+ T f(Arg1 a1, Arg2 a2) {
+ return (T){a1, a2};
+ }
+};
+
+template struct CompoundLiteral0<Point2D, int, float>;