public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108476] New: Please turn -Wreturn-type on by default for C
@ 2023-01-20  7:08 alexhenrie24 at gmail dot com
  2023-01-20  7:23 ` [Bug c/108476] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: alexhenrie24 at gmail dot com @ 2023-01-20  7:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108476

            Bug ID: 108476
           Summary: Please turn -Wreturn-type on by default for C
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexhenrie24 at gmail dot com
  Target Milestone: ---

According to the documentation, -Wreturn-type does the following:

    "Warn whenever a function is defined with a return type that defaults to
int. Also warn about any return statement with no return value in a function
whose return type is not void (falling off the end of the function body is
considered returning without a value)."

    https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

I feel strongly that gcc should turn on -Wreturn-type by default for the
following reasons:

* Not specifying the return value of a function that returns a non-void value
is almost always a bug.

* C99 and later do not allow declaring or defining a function without a return
type, so there's a good chance that code that omits the return type will break
when used with other compilers.

* GCC already turns the warning on by default for C++, and all but the most
educated of users do not expect C and C++ to be different in this regard, so it
gives a false sense of security when no such warnings appear when compiling C
code.

* Clang already turns the warning on by default for both C and C++, which goes
to show that the warning does not come up much in practice.

I've personally been bitten by forgetting to return a value from a function, so
I hope you will agree that -Wreturn-type is a sensible default to help spot
bugs sooner.

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

end of thread, other threads:[~2024-01-12 13:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-20  7:08 [Bug c/108476] New: Please turn -Wreturn-type on by default for C alexhenrie24 at gmail dot com
2023-01-20  7:23 ` [Bug c/108476] " pinskia at gcc dot gnu.org
2023-01-20  8:32 ` rguenth at gcc dot gnu.org
2023-01-20 10:13 ` jakub at gcc dot gnu.org
2023-01-23 16:40 ` alexhenrie24 at gmail dot com
2023-12-01  7:18 ` fw at gcc dot gnu.org
2024-01-12 13:43 ` xry111 at gcc dot gnu.org

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).