decl.c (finish_function): Also complain about no return in templates.
authorJason Merrill <jason@redhat.com>
Wed, 18 Dec 2002 06:26:58 +0000 (01:26 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 18 Dec 2002 06:26:58 +0000 (01:26 -0500)
        * decl.c (finish_function): Also complain about no return in
        templates.
        * semantics.c (finish_return_stmt): Also call check_return_expr in
        templates.
        * typeck.c (check_return_expr): In a template, just remember that we
        saw a return.

From-SVN: r60236

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/semantics.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/warn/noreturn-2.C [new file with mode: 0644]

index 1e50ff96905a080d9ac528bc7f46d1290597f007..67b90addcaa6b42ff1a3ea1273015239bf9808aa 100644 (file)
@@ -1,3 +1,12 @@
+2002-12-17  Jason Merrill  <jason@redhat.com>
+
+       * decl.c (finish_function): Also complain about no return in
+       templates.
+       * semantics.c (finish_return_stmt): Also call check_return_expr in 
+       templates.
+       * typeck.c (check_return_expr): In a template, just remember that we
+       saw a return.
+
 2002-12-16  Jason Merrill  <jason@redhat.com>
 
        * semantics.c (simplify_aggr_init_exprs_r): Don't change the type
index 2d6b4a4a28e5c60c42fe39a064ba4e94e2e6f75a..870a13dd28387357c0cec9374f6ff66abb5b3881 100644 (file)
@@ -14540,7 +14540,6 @@ finish_function (flags)
 
   /* Complain if there's just no return statement.  */
   if (warn_return_type
-      && !processing_template_decl
       && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE
       && !current_function_returns_value && !current_function_returns_null
       /* Don't complain if we abort or throw.  */
@@ -14548,7 +14547,7 @@ finish_function (flags)
       && !DECL_NAME (DECL_RESULT (fndecl))
       /* Normally, with -Wreturn-type, flow will complain.  Unless we're an
         inline function, as we might never be compiled separately.  */
-      && DECL_INLINE (fndecl))
+      && (DECL_INLINE (fndecl) || processing_template_decl))
     warning ("no return statement in function returning non-void");
     
   /* Clear out memory we no longer need.  */
index e402a72f894748d6b200eaa776b12036c920d7eb..42a740dd71f8f341b5ab14e818b252d83f365b03 100644 (file)
@@ -400,8 +400,7 @@ finish_return_stmt (expr)
 {
   tree r;
 
-  if (!processing_template_decl)
-    expr = check_return_expr (expr);
+  expr = check_return_expr (expr);
   if (!processing_template_decl)
     {
       if (DECL_DESTRUCTOR_P (current_function_decl))
index 1c78dd1d0574fd1d5b61423b4bc7deaaf937456e..769702b8a1d711fd1fed65c92b151e8df412cde9 100644 (file)
@@ -6172,6 +6172,12 @@ check_return_expr (retval)
       return NULL_TREE;
     }
 
+  if (processing_template_decl)
+    {
+      current_function_returns_value = 1;
+      return retval;
+    }
+  
   /* When no explicit return-value is given in a function with a named
      return value, the named return value is used.  */
   result = DECL_RESULT (current_function_decl);
diff --git a/gcc/testsuite/g++.dg/warn/noreturn-2.C b/gcc/testsuite/g++.dg/warn/noreturn-2.C
new file mode 100644 (file)
index 0000000..3b18e1d
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-options "-Wall" }
+
+template <class T>
+int f (T t) { }                        // { dg-warning "no return" }