This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Some low-hanging -Wunreachable-code fruits.
authorJarkko Hietaniemi <jhi@iki.fi>
Sun, 15 Jun 2014 13:41:30 +0000 (09:41 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 16 Jun 2014 01:00:07 +0000 (21:00 -0400)
commit81d52ecd50d856aa8879413261956d0801e7fd12
treeb672e3331504ebd1670bbc67be3f33e358fef061
parentd39195d4cbd0258917ad8f5f002fc6548080938a
Some low-hanging -Wunreachable-code fruits.

- after return/croak/die/exit, return/break are pointless
  (break is not a terminator/separator, it's a goto)
- after goto, another goto (!) is pointless
- in some cases (usually function ends) introduce explicit NOT_REACHED
  to make the noreturn nature clearer (do not do this everywhere, though,
  since that would mean adding NOT_REACHED after every croak)
- for the added NOT_REACHED also add /* NOTREACHED */ since
  NOT_REACHED is for gcc (and VC), while the comment is for linters
- declaring variables in switch blocks is just too fragile:
  it kind of works for narrowing the scope (which is nice),
  but breaks the moment there are initializations for the variables
  (the initializations will be skipped since the flow will bypass
  the start of the block); in some easy cases simply hoist the declarations
  out of the block and move them earlier

Note 1: Since after this patch the core is not yet -Wunreachable-code
clean, not enabling that via cflags.SH, one needs to -Accflags=... it.

Note 2: At least with the older gcc 4.4.7 there are far too many
"unreachable code" warnings, which seem to go away with gcc 4.8,
maybe better flow control analysis.  Therefore, the warning should
eventually be enabled only for modernish gccs (what about clang and
Intel cc?)
19 files changed:
cflags.SH
dump.c
ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm
gv.c
inline.h
mg.c
miniperlmain.c
op.c
perl.h
pp.c
pp_ctl.c
pp_pack.c
pp_sys.c
regcomp.c
regexec.c
regexp.h
sv.c
toke.c
utf8.c