[cfe-commits] r71825 - in /cfe/trunk: lib/Sema/SemaStmt.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-function-1.cpp
Anders Carlsson
andersca at mac.com
Thu May 14 17:48:33 PDT 2009
Author: andersca
Date: Thu May 14 19:48:27 2009
New Revision: 71825
URL: http://llvm.org/viewvc/llvm-project?rev=71825&view=rev
Log:
Instantiate return statements.
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=71825&r1=71824&r2=71825&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu May 14 19:48:27 2009
@@ -823,7 +823,7 @@
return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
}
- if (!RetValExp) {
+ if (!RetValExp && !FnRetType->isDependentType()) {
unsigned DiagID = diag::warn_return_missing_expr; // C90 6.6.6.4p4
// C99 6.8.6.4p1 (ext_ since GCC warns)
if (getLangOptions().C99) DiagID = diag::ext_return_missing_expr;
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=71825&r1=71824&r2=71825&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Thu May 14 19:48:27 2009
@@ -447,6 +447,7 @@
OwningStmtResult VisitExpr(Expr *E);
OwningStmtResult VisitLabelStmt(LabelStmt *S);
OwningStmtResult VisitGotoStmt(GotoStmt *S);
+ OwningStmtResult VisitReturnStmt(ReturnStmt *S);
// Base case. I'm supposed to ignore this.
OwningStmtResult VisitStmt(Stmt *S) {
@@ -499,6 +500,19 @@
S->getLabel()->getID());
}
+Sema::OwningStmtResult
+TemplateStmtInstantiator::VisitReturnStmt(ReturnStmt *S) {
+ Sema::OwningExprResult Result = SemaRef.ExprEmpty();
+ if (Expr *E = S->getRetValue()) {
+ Result = SemaRef.InstantiateExpr(E, TemplateArgs);
+
+ if (Result.isInvalid())
+ return SemaRef.StmtError();
+ }
+
+ return SemaRef.ActOnReturnStmt(S->getReturnLoc(), move(Result));
+}
+
Sema::OwningStmtResult
TemplateStmtInstantiator::VisitCompoundStmt(CompoundStmt *S) {
// FIXME: We need an *easy* RAII way to delete these statements if
Modified: cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp?rev=71825&r1=71824&r2=71825&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp Thu May 14 19:48:27 2009
@@ -37,3 +37,16 @@
};
template struct X3<int>;
+
+template <typename T> struct X4 {
+ T f() const {
+ return; // expected-warning{{non-void function 'f' should return a value}}
+ }
+
+ T g() const {
+ return 1; // expected-warning{{void function 'g' should not return a value}}
+ }
+};
+
+template struct X4<void>; // expected-note{{in instantiation of template class 'X4<void>' requested here}}
+template struct X4<int>; // expected-note{{in instantiation of template class 'X4<int>' requested here}}
More information about the cfe-commits
mailing list