Commit 8865587c authored by Paul Eggert's avatar Paul Eggert

Add -Wswitch to --enable-gcc-warnings

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.
parent 82198ed5
...@@ -928,10 +928,13 @@ else ...@@ -928,10 +928,13 @@ else
# option problematic. # option problematic.
nw="$nw -Wsuggest-attribute=pure" 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, # This part is merely for shortening the command line,
# since -Wno-FOO needs to be added below regardless. # since -Wno-FOO needs to be added below regardless.
nw="$nw -Wmissing-field-initializers" nw="$nw -Wmissing-field-initializers"
nw="$nw -Wswitch"
nw="$nw -Wtype-limits" nw="$nw -Wtype-limits"
nw="$nw -Wunused-parameter" nw="$nw -Wunused-parameter"
...@@ -948,7 +951,6 @@ else ...@@ -948,7 +951,6 @@ else
gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one 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-sign-compare]) # Too many warnings for now
gl_WARN_ADD([-Wno-type-limits]) # 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-unused-parameter]) # Too many warnings for now
gl_WARN_ADD([-Wno-format-nonliteral]) gl_WARN_ADD([-Wno-format-nonliteral])
......
...@@ -1268,6 +1268,8 @@ main (int argc, char **argv) ...@@ -1268,6 +1268,8 @@ main (int argc, char **argv)
this_file = argbuffer[i].what; this_file = argbuffer[i].what;
process_file (stdin, this_file, lang); process_file (stdin, this_file, lang);
break; break;
default:
error ("internal error: arg_type");
} }
} }
...@@ -2754,6 +2756,9 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2754,6 +2756,9 @@ consider_token (char *str, int len, int c, int *c_extp,
case st_C_struct: case st_C_struct:
case st_C_enum: case st_C_enum:
typdef = ttypeseen; typdef = ttypeseen;
break;
default:
break;
} }
break; break;
case ttypeseen: case ttypeseen:
...@@ -2770,8 +2775,11 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2770,8 +2775,11 @@ consider_token (char *str, int len, int c, int *c_extp,
case st_C_struct: case st_C_struct:
case st_C_enum: case st_C_enum:
return false; return false;
default:
return true;
} }
return true; default:
break;
} }
switch (toktype) switch (toktype)
...@@ -2804,6 +2812,8 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2804,6 +2812,8 @@ consider_token (char *str, int len, int c, int *c_extp,
fvdef = fvnone; fvdef = fvnone;
} }
return false; return false;
default:
break;
} }
if (structdef == skeyseen) if (structdef == skeyseen)
...@@ -2827,6 +2837,8 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2827,6 +2837,8 @@ consider_token (char *str, int len, int c, int *c_extp,
case st_C_objimpl: case st_C_objimpl:
objdef = oimplementation; objdef = oimplementation;
return false; return false;
default:
break;
} }
break; break;
case oimplementation: case oimplementation:
...@@ -2888,6 +2900,8 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2888,6 +2900,8 @@ consider_token (char *str, int len, int c, int *c_extp,
objdef = onone; objdef = onone;
} }
return false; return false;
default:
break;
} }
/* A function, variable or enum constant? */ /* A function, variable or enum constant? */
...@@ -2943,6 +2957,8 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2943,6 +2957,8 @@ consider_token (char *str, int len, int c, int *c_extp,
return false; return false;
} }
break; break;
default:
break;
} }
/* FALLTHRU */ /* FALLTHRU */
case fvnameseen: case fvnameseen:
...@@ -2959,8 +2975,12 @@ consider_token (char *str, int len, int c, int *c_extp, ...@@ -2959,8 +2975,12 @@ consider_token (char *str, int len, int c, int *c_extp,
fvdef = fvnameseen; /* function or variable */ fvdef = fvnameseen; /* function or variable */
*is_func_or_var = true; *is_func_or_var = true;
return true; return true;
default:
break;
} }
break; break;
default:
break;
} }
return false; return false;
...@@ -3470,6 +3490,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3470,6 +3490,8 @@ C_entries (int c_ext, FILE *inf)
fvdef = fignore; fvdef = fignore;
} }
break; break;
default:
break;
} }
if (structdef == stagseen && !cjava) if (structdef == stagseen && !cjava)
{ {
...@@ -3480,6 +3502,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3480,6 +3502,8 @@ C_entries (int c_ext, FILE *inf)
case dsharpseen: case dsharpseen:
savetoken = token; savetoken = token;
break; break;
default:
break;
} }
if (!yacc_rules || lp == newlb.buffer + 1) if (!yacc_rules || lp == newlb.buffer + 1)
{ {
...@@ -3508,7 +3532,7 @@ C_entries (int c_ext, FILE *inf) ...@@ -3508,7 +3532,7 @@ C_entries (int c_ext, FILE *inf)
break; break;
switch (objdef) switch (objdef)
{ {
case otagseen: case otagseen:
objdef = oignore; objdef = oignore;
make_C_tag (true); /* an Objective C class */ make_C_tag (true); /* an Objective C class */
break; break;
...@@ -3522,6 +3546,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3522,6 +3546,8 @@ C_entries (int c_ext, FILE *inf)
strcpy (token_name.buffer + toklen, ":"); strcpy (token_name.buffer + toklen, ":");
} }
break; break;
default:
break;
} }
if (structdef == stagseen) if (structdef == stagseen)
{ {
...@@ -3599,6 +3625,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3599,6 +3625,8 @@ C_entries (int c_ext, FILE *inf)
make_C_tag (true); /* an Objective C method */ make_C_tag (true); /* an Objective C method */
objdef = oinbody; objdef = oinbody;
break; break;
default:
break;
} }
switch (fvdef) switch (fvdef)
{ {
...@@ -3672,6 +3700,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3672,6 +3700,8 @@ C_entries (int c_ext, FILE *inf)
fvdef = fvnone; fvdef = fvnone;
} }
break; break;
default:
break;
} }
break; break;
case '(': case '(':
...@@ -3705,6 +3735,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3705,6 +3735,8 @@ C_entries (int c_ext, FILE *inf)
case flistseen: case flistseen:
fvdef = finlist; fvdef = finlist;
break; break;
default:
break;
} }
parlev++; parlev++;
break; break;
...@@ -3730,6 +3762,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3730,6 +3762,8 @@ C_entries (int c_ext, FILE *inf)
case finlist: case finlist:
fvdef = flistseen; fvdef = flistseen;
break; break;
default:
break;
} }
if (!instruct if (!instruct
&& (typdef == tend && (typdef == tend
...@@ -3801,6 +3835,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3801,6 +3835,8 @@ C_entries (int c_ext, FILE *inf)
bracelev = -1; bracelev = -1;
} }
break; break;
default:
break;
} }
switch (structdef) switch (structdef)
{ {
...@@ -3814,6 +3850,8 @@ C_entries (int c_ext, FILE *inf) ...@@ -3814,6 +3850,8 @@ C_entries (int c_ext, FILE *inf)
structdef = snone; structdef = snone;
make_C_tag (false); /* a struct or enum */ make_C_tag (false); /* a struct or enum */
break; break;
default:
break;
} }
bracelev += 1; bracelev += 1;
break; break;
......
...@@ -4295,6 +4295,9 @@ encode_invocation_designation (struct charset *charset, ...@@ -4295,6 +4295,9 @@ encode_invocation_designation (struct charset *charset,
else else
ENCODE_LOCKING_SHIFT_3; ENCODE_LOCKING_SHIFT_3;
break; break;
default:
break;
} }
} }
...@@ -7292,6 +7295,8 @@ produce_annotation (struct coding_system *coding, ptrdiff_t pos) ...@@ -7292,6 +7295,8 @@ produce_annotation (struct coding_system *coding, ptrdiff_t pos)
case CODING_ANNOTATE_CHARSET_MASK: case CODING_ANNOTATE_CHARSET_MASK:
produce_charset (coding, charbuf, pos); produce_charset (coding, charbuf, pos);
break; break;
default:
break;
} }
charbuf += len; charbuf += len;
} }
......
...@@ -226,8 +226,9 @@ for example, (type-of 1) returns `integer'. */) ...@@ -226,8 +226,9 @@ for example, (type-of 1) returns `integer'. */)
return Qfloat; return Qfloat;
case Lisp_Misc_Finalizer: case Lisp_Misc_Finalizer:
return Qfinalizer; return Qfinalizer;
default:
emacs_abort ();
} }
emacs_abort ();
case Lisp_Vectorlike: case Lisp_Vectorlike:
if (WINDOW_CONFIGURATIONP (object)) if (WINDOW_CONFIGURATIONP (object))
......
...@@ -2378,10 +2378,6 @@ struct it ...@@ -2378,10 +2378,6 @@ struct it
struct it_slice slice; struct it_slice slice;
ptrdiff_t image_id; ptrdiff_t image_id;
} image; } image;
/* method == GET_FROM_COMPOSITION */
struct {
Lisp_Object object;
} comp;
/* method == GET_FROM_STRETCH */ /* method == GET_FROM_STRETCH */
struct { struct {
Lisp_Object object; Lisp_Object object;
......
...@@ -596,6 +596,11 @@ The return value is BASE-VARIABLE. */) ...@@ -596,6 +596,11 @@ The return value is BASE-VARIABLE. */)
error ("Cannot make an internal variable an alias"); error ("Cannot make an internal variable an alias");
case SYMBOL_LOCALIZED: case SYMBOL_LOCALIZED:
error ("Don't know how to make a localized variable an alias"); 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 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
...@@ -640,6 +645,17 @@ default_toplevel_binding (Lisp_Object symbol) ...@@ -640,6 +645,17 @@ default_toplevel_binding (Lisp_Object symbol)
if (EQ (specpdl_symbol (pdl), symbol)) if (EQ (specpdl_symbol (pdl), symbol))
binding = pdl; binding = pdl;
break; 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; return binding;
...@@ -3462,6 +3478,17 @@ NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. ...@@ -3462,6 +3478,17 @@ NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'.
else else
result = Fcons (Fcons (sym, val), result); 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) ...@@ -3504,6 +3531,14 @@ mark_specpdl (void)
mark_object (specpdl_symbol (pdl)); mark_object (specpdl_symbol (pdl));
mark_object (specpdl_old_value (pdl)); mark_object (specpdl_old_value (pdl));
break; break;
case SPECPDL_UNWIND_PTR:
case SPECPDL_UNWIND_INT:
case SPECPDL_UNWIND_VOID:
break;
default:
emacs_abort ();
} }
} }
} }
......
...@@ -4353,12 +4353,13 @@ INLINE ptrdiff_t ...@@ -4353,12 +4353,13 @@ INLINE ptrdiff_t
lisp_word_count (ptrdiff_t nbytes) lisp_word_count (ptrdiff_t nbytes)
{ {
if (-1 >> 1 == -1) if (-1 >> 1 == -1)
switch (word_size) switch (word_size + 0)
{ {
case 2: return nbytes >> 1; case 2: return nbytes >> 1;
case 4: return nbytes >> 2; case 4: return nbytes >> 2;
case 8: return nbytes >> 3; case 8: return nbytes >> 3;
case 16: return nbytes >> 4; case 16: return nbytes >> 4;
default: break;
} }
return nbytes / word_size - (nbytes % word_size < 0); return nbytes / word_size - (nbytes % word_size < 0);
} }
......
...@@ -2799,12 +2799,8 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag) ...@@ -2799,12 +2799,8 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
: c_code == Sstring_fence) : c_code == Sstring_fence)
break; break;
switch (c_code) if (c_code == Scharquote || c_code == Sescape)
{ INC_BOTH (from, from_byte);
case Scharquote:
case Sescape:
INC_BOTH (from, from_byte);
}
INC_BOTH (from, from_byte); INC_BOTH (from, from_byte);
} }
INC_BOTH (from, from_byte); INC_BOTH (from, from_byte);
...@@ -3419,11 +3415,16 @@ do { prev_from = from; \ ...@@ -3419,11 +3415,16 @@ do { prev_from = from; \
case Sstring_fence: case Sstring_fence:
if (!nofence) goto string_end; if (!nofence) goto string_end;
break; break;
case Scharquote: case Scharquote:
case Sescape: case Sescape:
INC_FROM; INC_FROM;
startquotedinstring: startquotedinstring:
if (from >= end) goto endquoted; if (from >= end) goto endquoted;
break;
default:
break;
} }
INC_FROM; INC_FROM;
} }
......
...@@ -170,19 +170,13 @@ check_memory_limits (void) ...@@ -170,19 +170,13 @@ check_memory_limits (void)
if (new_warnlevel > warnlevel || new_warnlevel == warned_95) if (new_warnlevel > warnlevel || new_warnlevel == warned_95)
{ {
warnlevel = new_warnlevel; warnlevel = new_warnlevel;
switch (warnlevel) static char const *const warn_diagnostic[] =
{ {
case warned_75: "Warning: past 75% of memory limit",
(*warn_function) ("Warning: past 75% of memory limit"); "Warning: past 85% of memory limit",
break; "Warning: past 95% of memory limit"
};
case warned_85: warn_function (warn_diagnostic[warnlevel - 1]);
(*warn_function) ("Warning: past 85% of memory limit");
break;
case warned_95:
(*warn_function) ("Warning: past 95% of memory limit");
}
} }
/* Handle going down in usage levels, with some hysteresis. */ /* Handle going down in usage levels, with some hysteresis. */
else else
......
...@@ -1291,10 +1291,18 @@ window_relative_x_coord (struct window *w, enum window_part part, int x) ...@@ -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_box_width (w, RIGHT_MARGIN_AREA)
+ ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)) + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0)); ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0));
}
/* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */ case ON_NOTHING:
return 0; 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 ();
}
} }
......
...@@ -5895,6 +5895,13 @@ push_it (struct it *it, struct text_pos *position) ...@@ -5895,6 +5895,13 @@ push_it (struct it *it, struct text_pos *position)
case GET_FROM_STRETCH: case GET_FROM_STRETCH:
p->u.stretch.object = it->object; p->u.stretch.object = it->object;
break; 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->position = position ? *position : it->position;
p->current = it->current; p->current = it->current;
...@@ -6017,6 +6024,11 @@ pop_it (struct it *it) ...@@ -6017,6 +6024,11 @@ pop_it (struct it *it)
it->method = GET_FROM_BUFFER; it->method = GET_FROM_BUFFER;
it->object = it->w->contents; it->object = it->w->contents;
} }
break;
case GET_FROM_C_STRING:
break;
default:
emacs_abort ();
} }
it->end_charpos = p->end_charpos; it->end_charpos = p->end_charpos;
it->string_nchars = p->string_nchars; it->string_nchars = p->string_nchars;
......
...@@ -5407,6 +5407,8 @@ xg_scroll_callback (GtkRange *range, ...@@ -5407,6 +5407,8 @@ xg_scroll_callback (GtkRange *range,
? scroll_bar_after_handle : scroll_bar_below_handle); ? scroll_bar_after_handle : scroll_bar_below_handle);
bar->dragging = -1; bar->dragging = -1;
break; break;
default:
break;
} }
if (part != scroll_bar_nowhere) if (part != scroll_bar_nowhere)
...@@ -10193,6 +10195,9 @@ x_check_fullscreen (struct frame *f) ...@@ -10193,6 +10195,9 @@ x_check_fullscreen (struct frame *f)
case FULLSCREEN_HEIGHT: case FULLSCREEN_HEIGHT:
lval = Qfullheight; lval = Qfullheight;
height = x_display_pixel_height (dpyinfo); height = x_display_pixel_height (dpyinfo);
break;
default:
emacs_abort ();
} }
frame_size_history_add frame_size_history_add
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment