[cfe-commits] r72190 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaTemplateInstantiateExpr.cpp lib/Sema/SemaTemplateInstantiateStmt.cpp test/SemaTemplate/instantiate-expr-3.cpp
Douglas Gregor
dgregor at apple.com
Wed May 20 15:57:04 PDT 2009
Author: dgregor
Date: Wed May 20 17:57:03 2009
New Revision: 72190
URL: http://llvm.org/viewvc/llvm-project?rev=72190&view=rev
Log:
Fix template instantiation for compound statements so that it properly
passes the "isStmtExpr" flag, to suppress warnings about unused
expressions.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp
cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=72190&r1=72189&r2=72190&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed May 20 17:57:03 2009
@@ -2188,6 +2188,9 @@
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);
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72190&r1=72189&r2=72190&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Wed May 20 17:57:03 2009
@@ -486,8 +486,8 @@
}
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();
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp?rev=72190&r1=72189&r2=72190&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp Wed May 20 17:57:03 2009
@@ -136,22 +136,7 @@
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 @@
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);
+}
Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp?rev=72190&r1=72189&r2=72190&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp Wed May 20 17:57:03 2009
@@ -63,7 +63,7 @@
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}}
}
};
More information about the cfe-commits
mailing list