PR 29521 Confusing warning for return with expression in function returning void

Manuel López-Ibáñez lopezibanez@gmail.com
Thu Jan 18 18:00:00 GMT 2007


:ADDPATCH c:

Simple fix for PR 29521. Given the testcase:

void func ()
{
}

void func2 ()
{
    return func ();
}

The patch replaces:

warning: 'return' with a value, in function returning void

with:

ISO C forbids 'return' with expression in function returning void

OK for mainline?

2007-01-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

  PR c/29521
  * c-typeck.c (c_finish_return): Improve warning message.

testsuite/
  * gcc.dg/c90-return-1.c: Update output.
  * gcc.dg/c99-return-1.c: Likewise.
-------------- next part --------------
Index: gcc/testsuite/gcc.dg/c90-return-1.c
===================================================================
--- gcc/testsuite/gcc.dg/c90-return-1.c	(revision 120783)
+++ gcc/testsuite/gcc.dg/c90-return-1.c	(working copy)
@@ -13,5 +13,5 @@ void
 bar (void)
 {
   return 1; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "with a value" "return constraint violation" { target *-*-* } 15 } */
+  /* { dg-error "with expression" "return constraint violation" { target *-*-* } 15 } */
 }
Index: gcc/testsuite/gcc.dg/c99-return-1.c
===================================================================
--- gcc/testsuite/gcc.dg/c99-return-1.c	(revision 120783)
+++ gcc/testsuite/gcc.dg/c99-return-1.c	(working copy)
@@ -14,5 +14,5 @@ void
 bar (void)
 {
   return 1; /* { dg-bogus "warning" "warning in place of error" } */
-  /* { dg-error "with a value" "return constraint violation" { target *-*-* } 16 } */
+  /* { dg-error "with expression" "return constraint violation" { target *-*-* } 16 } */
 }
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 120783)
+++ gcc/c-typeck.c	(working copy)
@@ -6936,7 +6936,7 @@ c_finish_return (tree retval)
     {
       current_function_returns_null = 1;
       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
-	pedwarn ("%<return%> with a value, in function returning void");
+	pedwarn ("ISO C forbids %<return%> with expression in function returning void");
     }
   else
     {


More information about the Gcc-patches mailing list