diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2014-06-12 21:23:14 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2014-06-13 21:41:58 -0400 |
commit | 8c2b19724d117cecfa186d044abdbf766372c679 (patch) | |
tree | 05aa26abffa2a53a577c846d81bb8f2743b99817 /sv.c | |
parent | b017fe877ad78f04afaa3c1327fc46391f572bfb (diff) | |
download | perl-8c2b19724d117cecfa186d044abdbf766372c679.tar.gz |
Some low-hanging -Wunreachable-code fruits.
- after croak/die/exit (or return), break (or return!) are pointless
(break is not a terminator/separator, it's a promise of a jump)
- 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
(they will be skipped!); in some easy cases simply hoist the declarations
out of the block and move them earlier
There are still a few places left.
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -4215,7 +4215,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, SV* sstr, const I32 flags) else Perl_croak(aTHX_ "Bizarre copy of %s", type); } - break; + NOT_REACHED; /* NOTREACHED */ case SVt_REGEXP: upgregexp: @@ -11346,10 +11346,10 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p { char *ptr = ebuf + sizeof ebuf; bool tempalt = uv ? alt : FALSE; /* Vectors can't change alt */ + unsigned dig; zeros = 0; switch (base) { - unsigned dig; case 16: p = (char *)((c == 'X') ? PL_hexdigit + 16 : PL_hexdigit); do { @@ -14677,7 +14677,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv, return varname(gv, '$', 0, NULL, (I8)obase->op_private, FUV_SUBSCRIPT_ARRAY); } - break; + NOT_REACHED; /* NOTREACHED */ case OP_EXISTS: o = cUNOPx(obase)->op_first; @@ -14779,7 +14779,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv, ? '@' : '%', o->op_targ, NULL, 0, FUV_SUBSCRIPT_WITHIN); } - break; + NOT_REACHED; /* NOTREACHED */ } case OP_AASSIGN: |