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

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