]> granicus.if.org Git - clang/commitdiff
Template instantiation for C99 compound literals
authorDouglas Gregor <dgregor@apple.com>
Thu, 21 May 2009 23:48:18 +0000 (23:48 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 21 May 2009 23:48:18 +0000 (23:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72236 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
lib/Sema/SemaTemplateInstantiateExpr.cpp
lib/Sema/SemaType.cpp
test/SemaTemplate/instantiate-c99.cpp

index e819b1c10fa9cddb41565f0af9042d0816925ffd..0d2a2b8a0a1123f787cefd1fae8bdc16d9f68ddb 100644 (file)
@@ -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();
 
index 14eef13f8d015f52092212b10a17938e9004dbf8..fd88b934fbf30ddc4a877b0d57e6b78a42fe38c7 100644 (file)
@@ -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());
index e10a912ccfc0f550cb82661601b7646e1c1102de..19ff9bbd4ca507a22970b5ca0604bf630d165c71 100644 (file)
@@ -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;
index a617594f8852ea3f9cb18fed3f8c87757799c303..cf691cffad3639e96582841beb483dcdc060b575 100644 (file)
@@ -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>;