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.