re PR c/29521 (Confusing warning for return with expression in function returning...
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 13 Feb 2007 00:29:17 +0000 (00:29 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 13 Feb 2007 00:29:17 +0000 (00:29 +0000)
2007-02-13  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.

From-SVN: r121876

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr29521-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr29521.c [new file with mode: 0644]

index 0f91517b38b27cd155e7c382aeed9d99d8c2c230..a25d814af35442b09d7703f95b97d05dd855b646 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-13  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR c/29521
+       * c-typeck.c (c_finish_return): Improve warning message.
+
 2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        * alias.c (find_symbolic_term): Delete unused function.
index 013a206015f19a41376b76fcf5837a78baa10ebc..c807a7edfe9ef331cdbc886fa497390a0191d8a1 100644 (file)
@@ -6935,8 +6935,10 @@ c_finish_return (tree retval)
   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
     {
       current_function_returns_null = 1;
-      if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
+      if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
        pedwarn ("%<return%> with a value, in function returning void");
+      else if (pedantic)
+       pedwarn ("ISO C forbids %<return%> with expression, in function returning void");
     }
   else
     {
index 12555562b89413f533d6565caf273d32f4652f31..7245d64e25d23bbe7e91799c9d46dbd94deea7e7 100644 (file)
@@ -1,3 +1,9 @@
+2007-02-13  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR c/29521
+       * gcc.dg/c90-return-1.c: Update output.
+       * gcc.dg/c99-return-1.c: Likewise.
+       
 2007-02-13  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/30554
diff --git a/gcc/testsuite/gcc.dg/pr29521-2.c b/gcc/testsuite/gcc.dg/pr29521-2.c
new file mode 100644 (file)
index 0000000..734652c
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR 29521 : warning for return with expression in function returning void */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+void func (void) { }
+
+void func2 (void)
+{
+  return func (); /* { dg-error "ISO C forbids 'return' with expression" } */
+}
+
+void func3 (void)
+{
+  return 1; /* { dg-error "'return' with a value" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pr29521.c b/gcc/testsuite/gcc.dg/pr29521.c
new file mode 100644 (file)
index 0000000..b6fb535
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR 29521 : warning for return with expression in function returning void */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void func (void) { }
+
+void func2 (void)
+{
+  return func ();
+}
+
+void func3 (void)
+{
+  return 1;  /* { dg-warning "'return' with a value" } */
+}