public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Wextra and Wreturn-type interaction (PR7651)
@ 2007-02-12 22:11 Manuel López-Ibáñez
  2007-02-20 17:51 ` [PING] " Manuel López-Ibáñez
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel López-Ibáñez @ 2007-02-12 22:11 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]

:ADDPATCH C:

Wextra gives a warning when a function may return with and without a
value, for example:

foo (a)
{
  if (a > 0)
    return a;
}

However, this warning is completely redundant, since Wreturn-type
(that is enabled by -Wall) will give a warning for any  'return'
without value, in a function whose return-type is not 'void' and about
a 'return' with a value, in a function whose return-type is 'void'. I
was not able to construct an example for which Wextra warns but
Wreturn-type does not.

So this patch removes this warning from Wextra and improves the
description of Wreturn-type.

Boostrapped and regression tested.

OK for mainline?


2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

  PR middle-end/7651
  * doc/invoke.texi (Wreturn-type): Complete description.
  (Wextra): Delete item about return-type warning.
  * c-decl.c: Delete redundant Wextra warning.

testsuite/
  * gcc.dg/20030906-1.c: Replace Wextra with Wreturn-type.
  * gcc.dg/20030906-2.c: Likewise.
  * objc.dg/method-17.m: Add -Wreturn-type.
  * obj-c++.dg/method-21.mm: Likewise.

[-- Attachment #2: wextra-wreturn-type.diff --]
[-- Type: text/plain, Size: 5239 bytes --]

Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 121678)
+++ gcc/doc/invoke.texi	(working copy)
@@ -2653,9 +2653,13 @@ This warning is enabled by @option{-Wall
 
 @item -Wreturn-type
 @opindex Wreturn-type
-Warn whenever a function is defined with a return-type that defaults to
-@code{int}.  Also warn about any @code{return} statement with no
-return-value in a function whose return-type is not @code{void}.
+@opindex Wno-return-type
+Warn whenever a function is defined with a return-type that defaults
+to @code{int}.  Also warn about any @code{return} statement with no
+return-value in a function whose return-type is not @code{void}
+(falling off the end of the function body is considered returning
+without a value), and about a @code{return} statement with a
+expression in a function whose return-type is @code{void}.
 
 Also warn if the return type of a function has a type qualifier
 such as @code{const}.  For ISO C such a type qualifier has no effect,
@@ -2893,22 +2897,6 @@ messages for these events:
 
 @itemize @bullet
 @item
-A function can return either with or without a value.  (Falling
-off the end of the function body is considered returning without
-a value.)  For example, this function would evoke such a
-warning:
-
-@smallexample
-@group
-foo (a)
-@{
-  if (a > 0)
-    return a;
-@}
-@end group
-@end smallexample
-
-@item
 An expression-statement or the left-hand side of a comma expression
 contains no side effects.
 To suppress the warning, cast the unused expression to void.
Index: gcc/testsuite/gcc.dg/20030906-1.c
===================================================================
--- gcc/testsuite/gcc.dg/20030906-1.c	(revision 121678)
+++ gcc/testsuite/gcc.dg/20030906-1.c	(working copy)
@@ -2,7 +2,7 @@
    Copyright (C) 2003 Free Software Foundation Inc.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O -finline-functions -Wextra" } */
+/* { dg-options "-O -finline-functions -Wreturn-type" } */
 
 extern int i;
 extern int foo (void);
@@ -12,10 +12,10 @@ int foo (void)
 {
   if( i ) return 0;
   else    return 1;
-}		/* { dg-bogus "may return with or without a value" } */
+}
 
 int bar (void)
 {
-  if( i ) return;
+  if( i ) return; /* { dg-warning "'return' with no value, in function returning non-void" } */
   else    return 1;
-}		/* { dg-warning "may return with or without a value" } */
+}		
Index: gcc/testsuite/gcc.dg/20030906-2.c
===================================================================
--- gcc/testsuite/gcc.dg/20030906-2.c	(revision 121678)
+++ gcc/testsuite/gcc.dg/20030906-2.c	(working copy)
@@ -2,7 +2,7 @@
    Copyright (C) 2003 Free Software Foundation Inc.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O -finline-functions -Wextra" } */
+/* { dg-options "-O -finline-functions -Wreturn-type" } */
 
 extern int i;
 extern int foo (void);
@@ -10,9 +10,9 @@ extern int bar (void);
 
 int foo (void)
 {
-  if( i ) return;
+  if( i ) return; /* { dg-warning "'return' with no value, in function returning non-void" } */
   else    return 1;
-}		/* { dg-warning "may return with or without a value" } */
+}
 
 int bar (void)
 {
Index: gcc/testsuite/objc.dg/method-17.m
===================================================================
--- gcc/testsuite/objc.dg/method-17.m	(revision 121678)
+++ gcc/testsuite/objc.dg/method-17.m	(working copy)
@@ -1,7 +1,7 @@
 /* Test for spurious "may or may not return a value" warnings.  */
 
 /* { dg-do compile } */
-/* { dg-options "-Wextra" } */
+/* { dg-options "-Wreturn-type -Wextra" } */
 
 #include <objc/Object.h>
 
@@ -16,11 +16,11 @@ extern int bar;
 - (id) meth1 {
   if (bar)
     return [Object new];
-  return;
-} /* { dg-warning "this function may return with or without a value" } */
+  return; /* { dg-warning "'return' with no value, in function returning non-void" } */
+} 
 - (void) meth2 {
   if (!bar)
     return;
   bar = 0;
-} /* { dg-bogus "this function may return with or without a value" } */
+} /* { dg-bogus "'return' with no value, in function returning non-void" } */
 @end
Index: gcc/testsuite/obj-c++.dg/method-21.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/method-21.mm	(revision 121678)
+++ gcc/testsuite/obj-c++.dg/method-21.mm	(working copy)
@@ -1,6 +1,6 @@
 /* Test for spurious "may or may not return a value" warnings.  */
 /* { dg-do compile } */
-/* { dg-options "-Wextra" } */
+/* { dg-options "-Wreturn-type -Wextra" } */
 
 #include <objc/Object.h>
 
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 121678)
+++ gcc/c-decl.c	(working copy)
@@ -6774,13 +6774,6 @@ finish_function (void)
       TREE_NO_WARNING (fndecl) = 1;
     }
 
-  /* With just -Wextra, complain only if function returns both with
-     and without a value.  */
-  if (extra_warnings
-      && current_function_returns_value
-      && current_function_returns_null)
-    warning (OPT_Wextra, "this function may return with or without a value");
-
   /* Store the end of the function, so that we get good line number
      info for the epilogue.  */
   cfun->function_end_locus = input_location;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PING] Wextra and Wreturn-type interaction (PR7651)
  2007-02-12 22:11 Wextra and Wreturn-type interaction (PR7651) Manuel López-Ibáñez
@ 2007-02-20 17:51 ` Manuel López-Ibáñez
  2007-03-01 18:34   ` [PING^2] " Manuel López-Ibáñez
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel López-Ibáñez @ 2007-02-20 17:51 UTC (permalink / raw)
  To: gcc-patches

Please review: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html

Thanks,

Manuel.

On 12/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> :ADDPATCH C:
>
> Wextra gives a warning when a function may return with and without a
> value, for example:
>
> foo (a)
> {
>   if (a > 0)
>     return a;
> }
>
> However, this warning is completely redundant, since Wreturn-type
> (that is enabled by -Wall) will give a warning for any  'return'
> without value, in a function whose return-type is not 'void' and about
> a 'return' with a value, in a function whose return-type is 'void'. I
> was not able to construct an example for which Wextra warns but
> Wreturn-type does not.
>
> So this patch removes this warning from Wextra and improves the
> description of Wreturn-type.
>
> Boostrapped and regression tested.
>
> OK for mainline?
>
>
> 2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
>
>   PR middle-end/7651
>   * doc/invoke.texi (Wreturn-type): Complete description.
>   (Wextra): Delete item about return-type warning.
>   * c-decl.c: Delete redundant Wextra warning.
>
> testsuite/
>   * gcc.dg/20030906-1.c: Replace Wextra with Wreturn-type.
>   * gcc.dg/20030906-2.c: Likewise.
>   * objc.dg/method-17.m: Add -Wreturn-type.
>   * obj-c++.dg/method-21.mm: Likewise.
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PING^2] Wextra and Wreturn-type interaction (PR7651)
  2007-02-20 17:51 ` [PING] " Manuel López-Ibáñez
@ 2007-03-01 18:34   ` Manuel López-Ibáñez
  2007-03-19 21:52     ` Manuel López-Ibáñez
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-01 18:34 UTC (permalink / raw)
  To: gcc-patches

PING^2: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html

Thanks,

Manuel.

On 20/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> Please review: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html
>
> Thanks,
>
> Manuel.
>
> On 12/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> > :ADDPATCH C:
> >
> > Wextra gives a warning when a function may return with and without a
> > value, for example:
> >
> > foo (a)
> > {
> >   if (a > 0)
> >     return a;
> > }
> >
> > However, this warning is completely redundant, since Wreturn-type
> > (that is enabled by -Wall) will give a warning for any  'return'
> > without value, in a function whose return-type is not 'void' and about
> > a 'return' with a value, in a function whose return-type is 'void'. I
> > was not able to construct an example for which Wextra warns but
> > Wreturn-type does not.
> >
> > So this patch removes this warning from Wextra and improves the
> > description of Wreturn-type.
> >
> > Boostrapped and regression tested.
> >
> > OK for mainline?
> >
> >
> > 2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
> >
> >   PR middle-end/7651
> >   * doc/invoke.texi (Wreturn-type): Complete description.
> >   (Wextra): Delete item about return-type warning.
> >   * c-decl.c: Delete redundant Wextra warning.
> >
> > testsuite/
> >   * gcc.dg/20030906-1.c: Replace Wextra with Wreturn-type.
> >   * gcc.dg/20030906-2.c: Likewise.
> >   * objc.dg/method-17.m: Add -Wreturn-type.
> >   * obj-c++.dg/method-21.mm: Likewise.
> >
> >
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PING^2] Wextra and Wreturn-type interaction (PR7651)
  2007-03-01 18:34   ` [PING^2] " Manuel López-Ibáñez
@ 2007-03-19 21:52     ` Manuel López-Ibáñez
  2007-04-03 22:41       ` Manuel López-Ibáñez
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-19 21:52 UTC (permalink / raw)
  To: gcc-patches

PING^3 http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html

On 01/03/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> PING^2: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html
>
> Thanks,
>
> Manuel.
>
> On 20/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> > Please review: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html
> >
> > Thanks,
> >
> > Manuel.
> >
> > On 12/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> > > :ADDPATCH C:
> > >
> > > Wextra gives a warning when a function may return with and without a
> > > value, for example:
> > >
> > > foo (a)
> > > {
> > >   if (a > 0)
> > >     return a;
> > > }
> > >
> > > However, this warning is completely redundant, since Wreturn-type
> > > (that is enabled by -Wall) will give a warning for any  'return'
> > > without value, in a function whose return-type is not 'void' and about
> > > a 'return' with a value, in a function whose return-type is 'void'. I
> > > was not able to construct an example for which Wextra warns but
> > > Wreturn-type does not.
> > >
> > > So this patch removes this warning from Wextra and improves the
> > > description of Wreturn-type.
> > >
> > > Boostrapped and regression tested.
> > >
> > > OK for mainline?
> > >
> > >
> > > 2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
> > >
> > >   PR middle-end/7651
> > >   * doc/invoke.texi (Wreturn-type): Complete description.
> > >   (Wextra): Delete item about return-type warning.
> > >   * c-decl.c: Delete redundant Wextra warning.
> > >
> > > testsuite/
> > >   * gcc.dg/20030906-1.c: Replace Wextra with Wreturn-type.
> > >   * gcc.dg/20030906-2.c: Likewise.
> > >   * objc.dg/method-17.m: Add -Wreturn-type.
> > >   * obj-c++.dg/method-21.mm: Likewise.
> > >
> > >
> >
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PING^2] Wextra and Wreturn-type interaction (PR7651)
  2007-03-19 21:52     ` Manuel López-Ibáñez
@ 2007-04-03 22:41       ` Manuel López-Ibáñez
  0 siblings, 0 replies; 5+ messages in thread
From: Manuel López-Ibáñez @ 2007-04-03 22:41 UTC (permalink / raw)
  To: gcc-patches

PING^4:  http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html

On 19/03/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> PING^3 http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html
>
> On 01/03/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> > PING^2: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html
> >
> > Thanks,
> >
> > Manuel.
> >
> > On 20/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> > > Please review: http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01102.html
> > >
> > > Thanks,
> > >
> > > Manuel.
> > >
> > > On 12/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> > > > :ADDPATCH C:
> > > >
> > > > Wextra gives a warning when a function may return with and without a
> > > > value, for example:
> > > >
> > > > foo (a)
> > > > {
> > > >   if (a > 0)
> > > >     return a;
> > > > }
> > > >
> > > > However, this warning is completely redundant, since Wreturn-type
> > > > (that is enabled by -Wall) will give a warning for any  'return'
> > > > without value, in a function whose return-type is not 'void' and about
> > > > a 'return' with a value, in a function whose return-type is 'void'. I
> > > > was not able to construct an example for which Wextra warns but
> > > > Wreturn-type does not.
> > > >
> > > > So this patch removes this warning from Wextra and improves the
> > > > description of Wreturn-type.
> > > >
> > > > Boostrapped and regression tested.
> > > >
> > > > OK for mainline?
> > > >
> > > >
> > > > 2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
> > > >
> > > >   PR middle-end/7651
> > > >   * doc/invoke.texi (Wreturn-type): Complete description.
> > > >   (Wextra): Delete item about return-type warning.
> > > >   * c-decl.c: Delete redundant Wextra warning.
> > > >
> > > > testsuite/
> > > >   * gcc.dg/20030906-1.c: Replace Wextra with Wreturn-type.
> > > >   * gcc.dg/20030906-2.c: Likewise.
> > > >   * objc.dg/method-17.m: Add -Wreturn-type.
> > > >   * obj-c++.dg/method-21.mm: Likewise.
> > > >
> > > >
> > >
> >
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-04-03 22:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-12 22:11 Wextra and Wreturn-type interaction (PR7651) Manuel López-Ibáñez
2007-02-20 17:51 ` [PING] " Manuel López-Ibáñez
2007-03-01 18:34   ` [PING^2] " Manuel López-Ibáñez
2007-03-19 21:52     ` Manuel López-Ibáñez
2007-04-03 22:41       ` Manuel López-Ibáñez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).