]> granicus.if.org Git - clang/commitdiff
Fix template instantiation for compound statements so that it properly
authorDouglas Gregor <dgregor@apple.com>
Wed, 20 May 2009 22:57:03 +0000 (22:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 20 May 2009 22:57:03 +0000 (22:57 +0000)
passes the "isStmtExpr" flag, to suppress warnings about unused
expressions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72190 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaTemplateInstantiateExpr.cpp
lib/Sema/SemaTemplateInstantiateStmt.cpp
test/SemaTemplate/instantiate-expr-3.cpp

index e16f544abbb3e8d129516e9ac57507b766158b6b..9fc54e41499fcb74e19a01938d34e0f5e7d2d933 100644 (file)
@@ -2188,6 +2188,9 @@ public:
 
   OwningStmtResult InstantiateStmt(Stmt *S, 
                                    const TemplateArgumentList &TemplateArgs);
+  OwningStmtResult InstantiateCompoundStmt(CompoundStmt *S, 
+                                    const TemplateArgumentList &TemplateArgs,
+                                           bool isStmtExpr);
 
   Decl *InstantiateDecl(Decl *D, DeclContext *Owner,
                         const TemplateArgumentList &TemplateArgs);
index a93ad1132a6a36b3f68af44b944a00437ba1fd7d..8100ba421bf10d11fc28bc6270c546237ece8078 100644 (file)
@@ -486,8 +486,8 @@ TemplateExprInstantiator::VisitConditionalOperator(ConditionalOperator *E) {
 }
 
 Sema::OwningExprResult TemplateExprInstantiator::VisitStmtExpr(StmtExpr *E) {
-  Sema::OwningStmtResult SubStmt = SemaRef.InstantiateStmt(E->getSubStmt(),
-                                                           TemplateArgs);
+  Sema::OwningStmtResult SubStmt 
+    = SemaRef.InstantiateCompoundStmt(E->getSubStmt(), TemplateArgs, true);
   if (SubStmt.isInvalid())
     return SemaRef.ExprError();
   
index e83718e33de2544e0146b39cde0cb01a485df909..d635dff94c667f646ee1064f1b354483f4fa3f9b 100644 (file)
@@ -136,22 +136,7 @@ TemplateStmtInstantiator::VisitReturnStmt(ReturnStmt *S) {
 
 Sema::OwningStmtResult 
 TemplateStmtInstantiator::VisitCompoundStmt(CompoundStmt *S) {
-  ASTOwningVector<&ActionBase::DeleteStmt> Statements(SemaRef);
-  
-  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
-       B != BEnd; ++B) {
-    OwningStmtResult Result = Visit(*B);
-    if (Result.isInvalid())
-      return SemaRef.StmtError();
-
-    Statements.push_back(Result.takeAs<Stmt>());
-  }
-
-  return SemaRef.ActOnCompoundStmt(S->getLBracLoc(), S->getRBracLoc(),
-                                   Sema::MultiStmtArg(SemaRef,
-                                                      Statements.take(),
-                                                      Statements.size()),
-                                   /*isStmtExpr=*/false);
+  return SemaRef.InstantiateCompoundStmt(S, TemplateArgs, false);
 }
 
 Sema::OwningStmtResult 
@@ -437,3 +422,28 @@ Sema::InstantiateStmt(Stmt *S, const TemplateArgumentList &TemplateArgs) {
   TemplateStmtInstantiator Instantiator(*this, TemplateArgs);
   return Instantiator.Visit(S);
 }
+
+Sema::OwningStmtResult 
+Sema::InstantiateCompoundStmt(CompoundStmt *S, 
+                              const TemplateArgumentList &TemplateArgs,
+                              bool isStmtExpr) {
+  if (!S)
+    return Owned((Stmt *)0);
+
+  TemplateStmtInstantiator Instantiator(*this, TemplateArgs);
+  ASTOwningVector<&ActionBase::DeleteStmt> Statements(*this);
+  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
+       B != BEnd; ++B) {
+    OwningStmtResult Result = Instantiator.Visit(*B);
+    if (Result.isInvalid())
+      return StmtError();
+
+    Statements.push_back(Result.takeAs<Stmt>());
+  }
+
+  return ActOnCompoundStmt(S->getLBracLoc(), S->getRBracLoc(),
+                           Sema::MultiStmtArg(*this,
+                                              Statements.take(),
+                                              Statements.size()),
+                           isStmtExpr);
+}
index 69d2fe715d81d2f337501dfa2de18b361802a574..03386e187395979f26d2936ec8059b329598cbcb 100644 (file)
@@ -63,7 +63,7 @@ template struct Conditional0<int, int, int>;
 template<typename T>
 struct StatementExpr0 {
   void f(T t) {
-    (void)({ if (t) t = t + 17; }); // expected-error{{invalid}}
+    (void)({ if (t) t = t + 17; t + 12;}); // expected-error{{invalid}}
   }
 };