diff options
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/return.cpp | 13 |
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 37f8aed474..8e69caae5c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1183,6 +1183,10 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { bool ReturnsVoid = false; bool HasNoReturn = false; if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + // If the result type of the function is a dependent type, we don't know + // whether it will be void or not, so don't + if (FD->getResultType()->isDependentType()) + return; if (FD->getResultType()->isVoidType()) ReturnsVoid = true; if (FD->hasAttr<NoReturnAttr>()) @@ -1202,7 +1206,7 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { && (Diags.getDiagnosticLevel(diag::warn_suggest_noreturn_block) == Diagnostic::Ignored || !ReturnsVoid)) return; - // FIXME: Funtion try block + // FIXME: Function try block if (CompoundStmt *Compound = dyn_cast<CompoundStmt>(Body)) { switch (CheckFallThrough(Body)) { case MaybeFallThrough: diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index a73c261d97..5dd56b2221 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -892,7 +892,8 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { return StmtError(); if (FnRetType->isVoidType()) { - if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns) + if (RetValExp && !RetValExp->isTypeDependent()) { + // C99 6.8.6.4p1 (ext_ since GCC warns) unsigned D = diag::ext_return_has_expr; if (RetValExp->getType()->isVoidType()) D = diag::ext_return_has_void_expr; diff --git a/test/SemaCXX/return.cpp b/test/SemaCXX/return.cpp index 56bc71f519..03b0ddb879 100644 --- a/test/SemaCXX/return.cpp +++ b/test/SemaCXX/return.cpp @@ -3,3 +3,16 @@ int test1() { throw; } + +// PR5071 +template<typename T> T f() { } + +template<typename T> +void g(T t) { + return t * 2; // okay +} + +template<typename T> +T h() { + return 17; +} |