On 16/01/2014 03:45, Jonathan Wakely wrote: > On 16 January 2014 11:11, Sylvestre Ledru wrote: >> Hello, >> >> On 17/11/2013 17:47, Jonathan Wakely wrote: >>> On 17 November 2013 15:40, Sylvestre Ledru wrote: >>>> For "control reaches end of non-void function", I haven't activated by >>>> default and I called the option -Wfalloff-nonvoid-function >>>> Of course, that is just a proposal! :) Better names are welcome. >>> It was nearly called -Wmissing-return a decade ago, but got bundled >>> with -Wreturn-type, see >>> http://gcc.gnu.org/ml/gcc-patches/2002-02/msg02002.html >> As discussed on this mailing list, I proposed a patch on the gcc-patches >> mailing list. >> http://gcc.gnu.org/ml/gcc-patches/2014-01/msg00820.html >> >> Any chance one of you could review it? > I like the change in principle, but it's not up to me, I can't approve > front-end patches. I can comment on the docs and ChangeLog but I'm > not subscribed to gcc-patches so didn't get the mail. I'll send some > comments, could you please reply to your gcc-patches mail and include > my comments? Thanks. Following the comments you sent me, here it is:
> Does -Wreturn-type enable -Wmissing-return? If not, users who > currently use -Werror=return-type might be surprised when "missing > return" warnings are no longer errors., because they are controlled by > a different option. That would require users to add > -Werror=missing-return to their makefiles, which would not be > compatible with older versions of GCC. Actually, I wonder if -Wmissing-return should not be included by default ... If you do not agree, could you tell me how I could enable -Wmissing-return with both -Wreturn-type and -Wall? Now, the code (I haven't touched the testsuite, the archive remains the same). gcc/ChangeLog: 2014-01-23 Sylvestre Ledru <sylves...@debian.org> PR other/PR55189 * doc/invoke.texi: Update of the documentation (-Wreturn-type -Wmissing-return enabled by default) * tree-cfg.c: Likewise gcc/c-family/ChangeLog: 2014-01-23 Sylvestre Ledru <sylves...@debian.org> * c.opt: Extract -Wmissing-return from -Wreturn-type to return a warning when a return statement is missing. gcc/fortran/ChangeLog: 2014-01-23 Sylvestre Ledru <sylves...@debian.org> * options.c: Extract -Wmissing-return from -Wreturn-type to return a warning when a return statement is missing. Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt (révision 206953) +++ gcc/c-family/c.opt (copie de travail) @@ -673,9 +673,13 @@ Warn about returning a pointer/reference to a local or temporary variable. Wreturn-type -C ObjC C++ ObjC++ Var(warn_return_type) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) +C ObjC C++ ObjC++ Var(warn_return_type) Init(1) Warning Warn whenever a function's return type defaults to \"int\" (C), or about inconsistent return types (C++) +Wmissing-return +C ObjC C++ ObjC++ Var(warn_missing_return) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++, Wreturn-type) +Warn whenever control may reach end of non-void function + Wselector ObjC ObjC++ Var(warn_selector) Warning Warn if a selector has multiple methods Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (révision 206953) +++ gcc/doc/invoke.texi (copie de travail) @@ -255,7 +255,7 @@ -Winvalid-pch -Wlarger-than=@var{len} -Wunsafe-loop-optimizations @gol -Wlogical-op -Wlong-long @gol -Wmain -Wmaybe-uninitialized -Wmissing-braces -Wmissing-field-initializers @gol --Wmissing-include-dirs @gol +-Wmissing-include-dirs -Wmissing-return @gol -Wno-multichar -Wnonnull -Wno-overflow -Wopenmp-simd @gol -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpadded @gol -Wparentheses -Wpedantic-ms-format -Wno-pedantic-ms-format @gol @@ -3348,6 +3348,7 @@ -Wmain @r{(only for C/ObjC and unless} @option{-ffreestanding}@r{)} @gol -Wmaybe-uninitialized @gol -Wmissing-braces @r{(only for C/ObjC)} @gol +-Wmissing-return @gol -Wnonnull @gol -Wopenmp-simd @gol -Wparentheses @gol @@ -3810,7 +3811,11 @@ message, even when @option{-Wno-return-type} is specified. The only exceptions are @samp{main} and functions defined in system headers. -This warning is enabled by @option{-Wall}. +@item -Wmissing-return +@opindex Wmissing-return +@opindex Wno-missing-return +Warn whenever falling off the end of the function body (i.e. without +a return statement). @item -Wswitch @opindex Wswitch Index: gcc/fortran/options.c =================================================================== --- gcc/fortran/options.c (révision 206953) +++ gcc/fortran/options.c (copie de travail) @@ -717,6 +717,10 @@ warn_return_type = value; break; + case OPT_Wmissing_return: + warn_missing_return = value; + break; + case OPT_Wsurprising: gfc_option.warn_surprising = value; break; Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (révision 206953) +++ gcc/tree-cfg.c (copie de travail) @@ -8097,7 +8097,7 @@ /* If we see "return;" in some basic block, then we do reach the end without returning a value. */ - else if (warn_return_type + else if (warn_missing_return && !TREE_NO_WARNING (cfun->decl) && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) > 0 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (cfun->decl)))) @@ -8112,7 +8112,7 @@ location = gimple_location (last); if (location == UNKNOWN_LOCATION) location = cfun->function_end_locus; - warning_at (location, OPT_Wreturn_type, "control reaches end of non-void function"); + warning_at (location, OPT_Wmissing_return, "control reaches end of non-void function"); TREE_NO_WARNING (cfun->decl) = 1; break; }