public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94768] New: Wreturn-type should be error, not warning
@ 2020-04-26  7:09 dcb314 at hotmail dot com
  2020-04-26  7:29 ` [Bug c++/94768] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: dcb314 at hotmail dot com @ 2020-04-26  7:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94768
           Summary: Wreturn-type should be error, not warning
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

For this C++ code:

void g( int);

struct S
{
        int a;
        int b;

        S & operator = ( const S & that)
        {
                g( that.a);
        }
};

G++ produces only a warning, although it does give us a clue
what it is expecting:

$ /home/dcb/gcc/results/bin/gcc -c -g -O2 -Wall apr26d.cc
apr26d.cc: In member function ‘S& S::operator=(const S&)’:
apr26d.cc:12:2: warning: no return statement in function returning non-void
[-Wreturn-type]
   11 |   g( that.a);
  +++ |+  return *this;
   12 |  }
      |  ^
$ 

I have to add -Werror=return-type to get compilation to stop.

$ /home/dcb/gcc/results/bin/gcc -c -Werror=return-type apr26d.cc
apr26d.cc: In member function ‘S& S::operator=(const S&)’:
apr26d.cc:12:2: error: no return statement in function returning non-void
[-Werror=return-type]
   11 |   g( that.a);
  +++ |+  return *this;
   12 |  }
      |  ^
cc1plus: some warnings being treated as errors
$ 

I'll have a look at switching on Werror=return-type permanently locally.

IMHO, for a C++ function returning non-void, a complete absence of any return
statement in the function really should produce an error.

Yes a warning is a diagnostic and so conforms with ISO C++ rules,
but finding obvious bugs at compile time is preferable to runtime.

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
@ 2020-04-26  7:29 ` redi at gcc dot gnu.org
  2020-04-26  7:33 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-26  7:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Binderman from comment #0)
> IMHO, for a C++ function returning non-void, a complete absence of any
> return statement in the function really should produce an error.

This is a valid C++ program and it would be non-conforming to reject it. The
compiler can't even assume the program has undefined behaviour, because g(int)
could throw an exception, or do something that terminates, or simply never
return (e.g. go into an infinite loops with side effects like I/O).

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
  2020-04-26  7:29 ` [Bug c++/94768] " redi at gcc dot gnu.org
@ 2020-04-26  7:33 ` redi at gcc dot gnu.org
  2020-04-26  7:47 ` dcb314 at hotmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-26  7:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> This is a valid C++ program

s/program/translation unit/

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
  2020-04-26  7:29 ` [Bug c++/94768] " redi at gcc dot gnu.org
  2020-04-26  7:33 ` redi at gcc dot gnu.org
@ 2020-04-26  7:47 ` dcb314 at hotmail dot com
  2020-04-26  8:32 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dcb314 at hotmail dot com @ 2020-04-26  7:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> This is a valid C++ program and it would be non-conforming to reject it.

Surprising. The standard looks broken to me. Standards conformance
only really matters if GNU C++ is in standards conformance mode.

Most of the time, it is in its own GNU mode and so could do a more
useful job here rather than IMHO blindly following non-useful standards.

I checked the source code of the popular Fedora Linux distribution.
There are 32 examples of this problem in the C++ code, so they will
need fixing.

Interestingly, there are a whopping 258 examples in the C code, but that's a
separate issue.

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2020-04-26  7:47 ` dcb314 at hotmail dot com
@ 2020-04-26  8:32 ` pinskia at gcc dot gnu.org
  2020-04-26  8:33 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-26  8:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to David Binderman from comment #0)
> > IMHO, for a C++ function returning non-void, a complete absence of any
> > return statement in the function really should produce an error.
> 
> This is a valid C++ program and it would be non-conforming to reject it. The
> compiler can't even assume the program has undefined behaviour, because
> g(int) could throw an exception, or do something that terminates, or simply
> never return (e.g. go into an infinite loops with side effects like I/O).

Just to expand on this.  undefined at runtime behavior is not supposed to stop
compilation of a translation unit.

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
                   ` (3 preceding siblings ...)
  2020-04-26  8:32 ` pinskia at gcc dot gnu.org
@ 2020-04-26  8:33 ` pinskia at gcc dot gnu.org
  2020-04-26  9:39 ` redi at gcc dot gnu.org
  2020-04-26  9:44 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-26  8:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to David Binderman from comment #3)
> I checked the source code of the popular Fedora Linux distribution.
> There are 32 examples of this problem in the C++ code, so they will
> need fixing.
> 
> Interestingly, there are a whopping 258 examples in the C code, but that's a
> separate issue.

Note C and C++ have slightly different notice about "no return statement in
function returning non-void"; In C it is only undefined if the return value is
used while in C++ it is undefined the moment that the end of the function
happens.

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
                   ` (4 preceding siblings ...)
  2020-04-26  8:33 ` pinskia at gcc dot gnu.org
@ 2020-04-26  9:39 ` redi at gcc dot gnu.org
  2020-04-26  9:44 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-26  9:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Binderman from comment #3)
> Most of the time, it is in its own GNU mode and so could do a more
> useful job here rather than IMHO blindly following non-useful standards.

Nobody is "blindly following" anything. It's been discussed in detail by people
who know what they're talking about, over many years (including again when
-Wreturn-type was enabled by default for C++). Rejecting valid C++ code by
default is not OK.

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

* [Bug c++/94768] Wreturn-type should be error, not warning
  2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
                   ` (5 preceding siblings ...)
  2020-04-26  9:39 ` redi at gcc dot gnu.org
@ 2020-04-26  9:44 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-26  9:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=55189
         Resolution|INVALID                     |DUPLICATE

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Dup of PR 43943 (and others)

*** This bug has been marked as a duplicate of bug 43943 ***

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

end of thread, other threads:[~2020-04-26  9:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26  7:09 [Bug c++/94768] New: Wreturn-type should be error, not warning dcb314 at hotmail dot com
2020-04-26  7:29 ` [Bug c++/94768] " redi at gcc dot gnu.org
2020-04-26  7:33 ` redi at gcc dot gnu.org
2020-04-26  7:47 ` dcb314 at hotmail dot com
2020-04-26  8:32 ` pinskia at gcc dot gnu.org
2020-04-26  8:33 ` pinskia at gcc dot gnu.org
2020-04-26  9:39 ` redi at gcc dot gnu.org
2020-04-26  9:44 ` redi 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).