Skip to content

Commit

Permalink
Fix -Wimplicit-fallthrough warnings (#2760)
Browse files Browse the repository at this point in the history
* define FALLTHROUGH attribute statement macro and use it where needed
* break switch cases where needed
* CI: remove exempted compiler warning
  • Loading branch information
nilason committed Feb 14, 2023
1 parent 20bba91 commit fedef50
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ jobs:
env:
# TODO: -pedantic-errors here won't go through ./configure (with GNU C)
CFLAGS: -std=${{ matrix.c }} -fPIC -Wall -Wextra
-Wno-error=implicit-fallthrough
# TODO: -pedantic-errors here won't compile
CXXFLAGS: -std=${{ matrix.cpp }} -fPIC -Wall -Wextra
-Wno-error=implicit-fallthrough
run: .github/workflows/build_ubuntu-22.04.sh $HOME/install -Werror
2 changes: 2 additions & 0 deletions display/d.labels/do_labels.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,11 @@ int scan_ref(char *buf)
case 2:
if (!(xmatch(word2) || ymatch(word2)))
return 0;
FALLTHROUGH;
case 1:
if (xmatch(word1) || ymatch(word1))
return 1;
FALLTHROUGH;
default:
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion imagery/i.atcorr/geomcond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ void GeomCond::parse()
}
case 4:
campm = 1.0f; /* avhrr PM, case 4 must fall through to case 5 */
case 5: /* avhrr PM and avhrr AM */
FALLTHROUGH;
case 5: /* avhrr PM and avhrr AM */
{
cin >> month;
cin >> jday;
Expand Down
11 changes: 11 additions & 0 deletions include/grass/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@

static const char *GRASS_copyright UNUSED = "GRASS GNU GPL licensed Software";

/*!
\def FALLTHROUGH
\brief A macro for a fallthrough statement attribute
*/
#if (defined(__GNUC__) && __GNUC__ >= 7) || \
(defined(__clang__) && __clang_major__ >= 12)
#define FALLTHROUGH __attribute__((__fallthrough__))
#else
#define FALLTHROUGH ((void)0)
#endif

/* GRASS version, GRASS date, git short hash of last change in GRASS headers
* (and anything else in include)
*/
Expand Down
1 change: 1 addition & 0 deletions lib/bitmap/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ int BM_set_mode(int mode, int size)
case BM_FLAT:
case BM_SPARSE:
Mode = mode;
break;
default:
fprintf(stderr, "BM_set_mode: Unknown mode: %d\n", mode);
ret--;
Expand Down
2 changes: 2 additions & 0 deletions lib/gmath/la.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,13 @@ int G_matvect_extract_vector(mat_struct *mt, vtype vt, int indx)
case RVEC: {
mt->type = ROWVEC_;
mt->v_indx = indx;
break;
}

case CVEC: {
mt->type = COLVEC_;
mt->v_indx = indx;
break;
}

default: {
Expand Down
1 change: 1 addition & 0 deletions lib/nviz/map_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ int Nviz_set_attr(int id, int type, int desc, int src, const char *str_value,

break;
}
FALLTHROUGH;
default: {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ogsf/gvl_calc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ int mc33_process_cube(int c_ndx, float *v)
case 7:
return OFFSET_T7_1 + m_config; /* 7.1 */
};
break; /* will not reach this as previous switch is exhaustive */

case 8:
return OFFSET_T8 + m_config;
Expand Down Expand Up @@ -558,6 +559,7 @@ int mc33_process_cube(int c_ndx, float *v)
default:
fprintf(stderr, "Marching Cubes: Impossible case 13?\n");
}
break; /* will not reach this as previous switch is exhaustive */

case 14:
return OFFSET_T14 + m_config;
Expand Down
2 changes: 2 additions & 0 deletions ps/ps.map/scan_ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ int scan_ref(char *buf, int *xref, int *yref)
lowercase(word2);
if (!(xmatch(word2, xref) || ymatch(word2, yref)))
return 0;
FALLTHROUGH;
case 1:
lowercase(word1);
if (xmatch(word1, xref) || ymatch(word1, yref))
return 1;
FALLTHROUGH;
default:
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions vector/v.in.dxf/dxf_to_vect.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int dxf_to_vect(struct dxf_file *dxf, struct Map_info *Map)
case 30:
dxf_ext.B = atof(dxf_buf);
bounds++;
FALLTHROUGH;
default:
break;
}
Expand Down

0 comments on commit fedef50

Please sign in to comment.