]> granicus.if.org Git - clang/commitdiff
When the return type of a function is dependent, don't perform any
authorDouglas Gregor <dgregor@apple.com>
Thu, 1 Oct 2009 23:25:31 +0000 (23:25 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 1 Oct 2009 23:25:31 +0000 (23:25 +0000)
of the flow-control checks for falling off the end of a function,
since the return type may instantiate to void. Similarly, if a
return statement has an expression and the return type of the function
is void, don't complain if the expression is type-dependent, since
that type could instantiate to void.

Fixes PR5071.

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

lib/Sema/SemaDecl.cpp
lib/Sema/SemaStmt.cpp
test/SemaCXX/return.cpp

index 37f8aed474480f7b84ed78f7a65fd7554eacd4b1..8e69caae5c47d6a6fce442eb8c7085d8ec73d5d6 100644 (file)
@@ -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:
index a73c261d97f686834ceb1f3f0ce6e05e2393e542..5dd56b22211a45113c814812224dc54a536cee98 100644 (file)
@@ -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;
index 56bc71f51910bdf7cb205a15bec86b186c18fff8..03b0ddb87965873ccc2404bb7368ffd0330938d8 100644 (file)
@@ -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;
+}