Template instantiation for C99 compound literals
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72236 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index e819b1c..0d2a2b8 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2719,8 +2719,9 @@
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 14eef13..fd88b93 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -49,7 +49,7 @@
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::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 e10a912..19ff9bb 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1090,6 +1090,12 @@
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;