[cfe-commits] r83222 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaStmt.cpp test/SemaCXX/return.cpp

Douglas Gregor dgregor at apple.com
Thu Oct 1 16:25:31 PDT 2009


Author: dgregor
Date: Thu Oct  1 18:25:31 2009
New Revision: 83222

URL: http://llvm.org/viewvc/llvm-project?rev=83222&view=rev
Log:
When the return type of a function is dependent, don't perform any
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.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaCXX/return.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=83222&r1=83221&r2=83222&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct  1 18:25:31 2009
@@ -1183,6 +1183,10 @@
   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 @@
       && (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:

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=83222&r1=83221&r2=83222&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Oct  1 18:25:31 2009
@@ -892,7 +892,8 @@
     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;

Modified: cfe/trunk/test/SemaCXX/return.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return.cpp?rev=83222&r1=83221&r2=83222&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/return.cpp (original)
+++ cfe/trunk/test/SemaCXX/return.cpp Thu Oct  1 18:25:31 2009
@@ -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;
+}





More information about the cfe-commits mailing list