From 8865587c55f251ac624e6730505de66d15b28562 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 16 Sep 2015 14:40:53 -0700 Subject: [PATCH] Add -Wswitch to --enable-gcc-warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Make --enable-gcc-warnings a bit pickier, by also using -Wswitch. * configure.ac (WERROR_CFLAGS): Don’t add -Wno-switch. * lib-src/etags.c (main, consider_token, C_entries): * src/coding.c (encode_invocation_designation): * src/data.c (Ftype_of): * src/eval.c (Fdefvaralias, default_toplevel_binding) (Fbacktrace__locals, mark_specpdl): * src/lisp.h (record_xmalloc): * src/syntax.c (scan_lists, scan_sexps_forward): * src/window.c (window_relative_x_coord): * src/xdisp.c (push_it, pop_it): * src/xterm.c (xg_scroll_callback, x_check_fullscreen): Error out or do nothing (as appropriate) if a switch statement with an enum value does not cover all of the enum. * src/dispextern.h (struct iterator_stack_entry.u.comp): Remove unused member discovered by using -Wswitch. * src/lisp.h (record_xmalloc): Add a ‘+ 0’ to pacify -Wswitch. * src/vm-limit.c (check_memory_limits): Simplify warning-diagnostic computation by using a table. --- configure.ac | 6 ++++-- lib-src/etags.c | 42 ++++++++++++++++++++++++++++++++++++++++-- src/coding.c | 5 +++++ src/data.c | 3 ++- src/dispextern.h | 4 ---- src/eval.c | 35 +++++++++++++++++++++++++++++++++++ src/lisp.h | 3 ++- src/syntax.c | 13 +++++++------ src/vm-limit.c | 18 ++++++------------ src/window.c | 14 +++++++++++--- src/xdisp.c | 12 ++++++++++++ src/xterm.c | 5 +++++ 12 files changed, 129 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index f86d29ed58b..d537f73c939 100644 --- a/configure.ac +++ b/configure.ac @@ -928,10 +928,13 @@ else # option problematic. nw="$nw -Wsuggest-attribute=pure" + # This part is merely for shortening the command line, + # since -Wall implies -Wswitch. + nw="$nw -Wswitch" + # This part is merely for shortening the command line, # since -Wno-FOO needs to be added below regardless. nw="$nw -Wmissing-field-initializers" - nw="$nw -Wswitch" nw="$nw -Wtype-limits" nw="$nw -Wunused-parameter" @@ -948,7 +951,6 @@ else gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now gl_WARN_ADD([-Wno-type-limits]) # Too many warnings for now - gl_WARN_ADD([-Wno-switch]) # Too many warnings for now gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now gl_WARN_ADD([-Wno-format-nonliteral]) diff --git a/lib-src/etags.c b/lib-src/etags.c index 7baff8cbfe8..791722d4b66 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -1268,6 +1268,8 @@ main (int argc, char **argv) this_file = argbuffer[i].what; process_file (stdin, this_file, lang); break; + default: + error ("internal error: arg_type"); } } @@ -2754,6 +2756,9 @@ consider_token (char *str, int len, int c, int *c_extp, case st_C_struct: case st_C_enum: typdef = ttypeseen; + break; + default: + break; } break; case ttypeseen: @@ -2770,8 +2775,11 @@ consider_token (char *str, int len, int c, int *c_extp, case st_C_struct: case st_C_enum: return false; + default: + return true; } - return true; + default: + break; } switch (toktype) @@ -2804,6 +2812,8 @@ consider_token (char *str, int len, int c, int *c_extp, fvdef = fvnone; } return false; + default: + break; } if (structdef == skeyseen) @@ -2827,6 +2837,8 @@ consider_token (char *str, int len, int c, int *c_extp, case st_C_objimpl: objdef = oimplementation; return false; + default: + break; } break; case oimplementation: @@ -2888,6 +2900,8 @@ consider_token (char *str, int len, int c, int *c_extp, objdef = onone; } return false; + default: + break; } /* A function, variable or enum constant? */ @@ -2943,6 +2957,8 @@ consider_token (char *str, int len, int c, int *c_extp, return false; } break; + default: + break; } /* FALLTHRU */ case fvnameseen: @@ -2959,8 +2975,12 @@ consider_token (char *str, int len, int c, int *c_extp, fvdef = fvnameseen; /* function or variable */ *is_func_or_var = true; return true; + default: + break; } break; + default: + break; } return false; @@ -3470,6 +3490,8 @@ C_entries (int c_ext, FILE *inf) fvdef = fignore; } break; + default: + break; } if (structdef == stagseen && !cjava) { @@ -3480,6 +3502,8 @@ C_entries (int c_ext, FILE *inf) case dsharpseen: savetoken = token; break; + default: + break; } if (!yacc_rules || lp == newlb.buffer + 1) { @@ -3508,7 +3532,7 @@ C_entries (int c_ext, FILE *inf) break; switch (objdef) { - case otagseen: + case otagseen: objdef = oignore; make_C_tag (true); /* an Objective C class */ break; @@ -3522,6 +3546,8 @@ C_entries (int c_ext, FILE *inf) strcpy (token_name.buffer + toklen, ":"); } break; + default: + break; } if (structdef == stagseen) { @@ -3599,6 +3625,8 @@ C_entries (int c_ext, FILE *inf) make_C_tag (true); /* an Objective C method */ objdef = oinbody; break; + default: + break; } switch (fvdef) { @@ -3672,6 +3700,8 @@ C_entries (int c_ext, FILE *inf) fvdef = fvnone; } break; + default: + break; } break; case '(': @@ -3705,6 +3735,8 @@ C_entries (int c_ext, FILE *inf) case flistseen: fvdef = finlist; break; + default: + break; } parlev++; break; @@ -3730,6 +3762,8 @@ C_entries (int c_ext, FILE *inf) case finlist: fvdef = flistseen; break; + default: + break; } if (!instruct && (typdef == tend @@ -3801,6 +3835,8 @@ C_entries (int c_ext, FILE *inf) bracelev = -1; } break; + default: + break; } switch (structdef) { @@ -3814,6 +3850,8 @@ C_entries (int c_ext, FILE *inf) structdef = snone; make_C_tag (false); /* a struct or enum */ break; + default: + break; } bracelev += 1; break; diff --git a/src/coding.c b/src/coding.c index 1544f319b00..d14e562ce9a 100644 --- a/src/coding.c +++ b/src/coding.c @@ -4295,6 +4295,9 @@ encode_invocation_designation (struct charset *charset, else ENCODE_LOCKING_SHIFT_3; break; + + default: + break; } } @@ -7292,6 +7295,8 @@ produce_annotation (struct coding_system *coding, ptrdiff_t pos) case CODING_ANNOTATE_CHARSET_MASK: produce_charset (coding, charbuf, pos); break; + default: + break; } charbuf += len; } diff --git a/src/data.c b/src/data.c index 88c5a309859..34265b7ecdc 100644 --- a/src/data.c +++ b/src/data.c @@ -226,8 +226,9 @@ for example, (type-of 1) returns `integer'. */) return Qfloat; case Lisp_Misc_Finalizer: return Qfinalizer; + default: + emacs_abort (); } - emacs_abort (); case Lisp_Vectorlike: if (WINDOW_CONFIGURATIONP (object)) diff --git a/src/dispextern.h b/src/dispextern.h index e5adeab0dc0..e44b70bf562 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -2378,10 +2378,6 @@ struct it struct it_slice slice; ptrdiff_t image_id; } image; - /* method == GET_FROM_COMPOSITION */ - struct { - Lisp_Object object; - } comp; /* method == GET_FROM_STRETCH */ struct { Lisp_Object object; diff --git a/src/eval.c b/src/eval.c index 77d435acbe6..b42f9047257 100644 --- a/src/eval.c +++ b/src/eval.c @@ -596,6 +596,11 @@ The return value is BASE-VARIABLE. */) error ("Cannot make an internal variable an alias"); case SYMBOL_LOCALIZED: error ("Don't know how to make a localized variable an alias"); + case SYMBOL_PLAINVAL: + case SYMBOL_VARALIAS: + break; + default: + emacs_abort (); } /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html @@ -640,6 +645,17 @@ default_toplevel_binding (Lisp_Object symbol) if (EQ (specpdl_symbol (pdl), symbol)) binding = pdl; break; + + case SPECPDL_UNWIND: + case SPECPDL_UNWIND_PTR: + case SPECPDL_UNWIND_INT: + case SPECPDL_UNWIND_VOID: + case SPECPDL_BACKTRACE: + case SPECPDL_LET_LOCAL: + break; + + default: + emacs_abort (); } } return binding; @@ -3462,6 +3478,17 @@ NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. else result = Fcons (Fcons (sym, val), result); } + break; + + case SPECPDL_UNWIND: + case SPECPDL_UNWIND_PTR: + case SPECPDL_UNWIND_INT: + case SPECPDL_UNWIND_VOID: + case SPECPDL_BACKTRACE: + break; + + default: + emacs_abort (); } } } @@ -3504,6 +3531,14 @@ mark_specpdl (void) mark_object (specpdl_symbol (pdl)); mark_object (specpdl_old_value (pdl)); break; + + case SPECPDL_UNWIND_PTR: + case SPECPDL_UNWIND_INT: + case SPECPDL_UNWIND_VOID: + break; + + default: + emacs_abort (); } } } diff --git a/src/lisp.h b/src/lisp.h index acbd679b44b..15fe40db780 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4353,12 +4353,13 @@ INLINE ptrdiff_t lisp_word_count (ptrdiff_t nbytes) { if (-1 >> 1 == -1) - switch (word_size) + switch (word_size + 0) { case 2: return nbytes >> 1; case 4: return nbytes >> 2; case 8: return nbytes >> 3; case 16: return nbytes >> 4; + default: break; } return nbytes / word_size - (nbytes % word_size < 0); } diff --git a/src/syntax.c b/src/syntax.c index de45c50ca3f..55a4ba0abd4 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -2799,12 +2799,8 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag) : c_code == Sstring_fence) break; - switch (c_code) - { - case Scharquote: - case Sescape: - INC_BOTH (from, from_byte); - } + if (c_code == Scharquote || c_code == Sescape) + INC_BOTH (from, from_byte); INC_BOTH (from, from_byte); } INC_BOTH (from, from_byte); @@ -3419,11 +3415,16 @@ do { prev_from = from; \ case Sstring_fence: if (!nofence) goto string_end; break; + case Scharquote: case Sescape: INC_FROM; startquotedinstring: if (from >= end) goto endquoted; + break; + + default: + break; } INC_FROM; } diff --git a/src/vm-limit.c b/src/vm-limit.c index ab102e32623..503aaaebf8a 100644 --- a/src/vm-limit.c +++ b/src/vm-limit.c @@ -170,19 +170,13 @@ check_memory_limits (void) if (new_warnlevel > warnlevel || new_warnlevel == warned_95) { warnlevel = new_warnlevel; - switch (warnlevel) + static char const *const warn_diagnostic[] = { - case warned_75: - (*warn_function) ("Warning: past 75% of memory limit"); - break; - - case warned_85: - (*warn_function) ("Warning: past 85% of memory limit"); - break; - - case warned_95: - (*warn_function) ("Warning: past 95% of memory limit"); - } + "Warning: past 75% of memory limit", + "Warning: past 85% of memory limit", + "Warning: past 95% of memory limit" + }; + warn_function (warn_diagnostic[warnlevel - 1]); } /* Handle going down in usage levels, with some hysteresis. */ else diff --git a/src/window.c b/src/window.c index f6fe0cdb059..f1af68eff18 100644 --- a/src/window.c +++ b/src/window.c @@ -1291,10 +1291,18 @@ window_relative_x_coord (struct window *w, enum window_part part, int x) + window_box_width (w, RIGHT_MARGIN_AREA) + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)) ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0)); - } - /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */ - return 0; + case ON_NOTHING: + case ON_VERTICAL_BORDER: + case ON_VERTICAL_SCROLL_BAR: + case ON_HORIZONTAL_SCROLL_BAR: + case ON_RIGHT_DIVIDER: + case ON_BOTTOM_DIVIDER: + return 0; + + default: + emacs_abort (); + } } diff --git a/src/xdisp.c b/src/xdisp.c index b86307776e2..a3224e2510f 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -5895,6 +5895,13 @@ push_it (struct it *it, struct text_pos *position) case GET_FROM_STRETCH: p->u.stretch.object = it->object; break; + case GET_FROM_BUFFER: + case GET_FROM_DISPLAY_VECTOR: + case GET_FROM_STRING: + case GET_FROM_C_STRING: + break; + default: + emacs_abort (); } p->position = position ? *position : it->position; p->current = it->current; @@ -6017,6 +6024,11 @@ pop_it (struct it *it) it->method = GET_FROM_BUFFER; it->object = it->w->contents; } + break; + case GET_FROM_C_STRING: + break; + default: + emacs_abort (); } it->end_charpos = p->end_charpos; it->string_nchars = p->string_nchars; diff --git a/src/xterm.c b/src/xterm.c index 9ee76e967e1..13e1902a0bb 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -5407,6 +5407,8 @@ xg_scroll_callback (GtkRange *range, ? scroll_bar_after_handle : scroll_bar_below_handle); bar->dragging = -1; break; + default: + break; } if (part != scroll_bar_nowhere) @@ -10193,6 +10195,9 @@ x_check_fullscreen (struct frame *f) case FULLSCREEN_HEIGHT: lval = Qfullheight; height = x_display_pixel_height (dpyinfo); + break; + default: + emacs_abort (); } frame_size_history_add -- 2.39.2