https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92289
Bug ID: 92289 Summary: Worse "control reaches end of non-void function" diagnostic with undefined sanitizer Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: TonyELewis at hotmail dot com Target Milestone: --- When I use Godbolt's GCC (9.2 or trunk ("10.0.0 20191022 (experimental)")) to compile: ~~~ void throw_sum( int a, int b ) { throw a + b; } #define THROW_WITH_LINE_NUM_ADDED( x ) throw_sum( x, __LINE__ ) bool f( const bool &prm_val ) { if ( prm_val ) { return true; } THROW_WITH_LINE_NUM_ADDED( 0 ); } ~~~ ...with `-Werror` I get a helpful warning (promoted to error): ~~~ <source>: In function 'bool f(const bool&)': <source>:9:1: error: control reaches end of non-void function [-Werror=return-type] 9 | } | ^ cc1plus: all warnings being treated as errors Compiler returned: 1 ~~~ ...but if I turn on UBSan (ie change the options to `-Werror -fsanitize=undefined`), I get: ~~~ <source>: In function 'bool f(const bool&)': <source>:3:49: error: control reaches end of non-void function [-Werror=return-type] 3 | #define THROW_WITH_LINE_NUM_ADDED( x ) throw_sum( x, __LINE__ ) | ~~~~~~~~~^~~~~~~~~~~~~~~ <source>:8:4: note: in expansion of macro 'THROW_WITH_LINE_NUM_ADDED' 8 | THROW_WITH_LINE_NUM_ADDED( 0 ); | ^~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors Compiler returned: 1 ~~~ ...which I think is much less helpful. I don't think that enabling runtime sanitizer checks should reduce the quality of the compiler's diagnostics. Thanks very much to all who work on GCC.