From: Douglas Gregor Date: Thu, 21 May 2009 23:48:18 +0000 (+0000) Subject: Template instantiation for C99 compound literals X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=690dc7f4f2c0fe87409839b7560c19dee7832195;p=clang 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 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); @@ -288,6 +288,26 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitCallExpr(CallExpr *E) { E->getRParenLoc()); } +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()); 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; template struct DesigArrayRangeInit0; // expected-note{{instantiation}} + +// --------------------------------------------------------------------- +// Compound literals +// --------------------------------------------------------------------- +template +struct CompoundLiteral0 { + T f(Arg1 a1, Arg2 a2) { + return (T){a1, a2}; + } +}; + +template struct CompoundLiteral0;