summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2024-03-05 08:29:15 +0000
committerVincent Sanders <vince@kyllikki.org>2024-03-05 08:29:15 +0000
commit618143239846e695f55a25c6beb8d5341869794b (patch)
tree7d53b8dbcf22c56fbe18d7a2de8cc5b7aec21911
parent583ec7268083fa2f4005067e0314ff9a56e62664 (diff)
downloadnetsurf-vince/fallthrough.tar.gz
netsurf-vince/fallthrough.tar.bz2
use attributes to indicate switch fall through instead of commentsvince/fallthrough
-rw-r--r--Makefile8
-rw-r--r--content/handlers/css/hints.c10
-rw-r--r--content/handlers/html/box_inspect.c3
-rw-r--r--content/handlers/html/dom_event.c3
-rw-r--r--content/handlers/html/interaction.c6
-rw-r--r--content/handlers/html/layout_flex.c4
-rw-r--r--content/handlers/html/redraw_border.c9
-rw-r--r--content/handlers/html/script.c1
-rw-r--r--content/handlers/html/table.c49
-rw-r--r--content/handlers/image/webp.c2
-rw-r--r--content/handlers/javascript/duktape/dukky.c2
-rw-r--r--frontends/gtk/download.c5
-rw-r--r--frontends/gtk/search.c2
-rw-r--r--frontends/windows/download.c2
-rw-r--r--frontends/windows/window.c2
-rw-r--r--utils/utils.h27
16 files changed, 85 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index 5cb55561f..18665ed3d 100644
--- a/Makefile
+++ b/Makefile
@@ -90,13 +90,13 @@ ifeq ($(call cc_ver_ge,4,6),1)
endif
ifeq ($(TOOLCHAIN),gcc)
- # Implicit fallthrough warnings suppressed by comment
+ # Implicit fallthrough warnings
ifeq ($(call cc_ver_ge,7,1),1)
- COMMON_WARNFLAGS += -Wimplicit-fallthrough=3
+ COMMON_WARNFLAGS += -Wimplicit-fallthrough=5
endif
else
- # clang uses [[clang::fallthrough]] to annotate fallthrough instead of comments
- COMMON_WARNFLAGS += -Wno-implicit-fallthrough
+ # non gcc has different warning syntax
+ COMMON_WARNFLAGS += -Wimplicit-fallthrough
endif
# deal with chaging warning flags for different platforms
diff --git a/content/handlers/css/hints.c b/content/handlers/css/hints.c
index 145cf8185..0f246a64c 100644
--- a/content/handlers/css/hints.c
+++ b/content/handlers/css/hints.c
@@ -1650,22 +1650,22 @@ css_error node_presentational_hint(void *pw, void *node,
css_hint_width(pw, node);
css_hint_table_cell_border_padding(pw, node);
css_hint_white_space_nowrap(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_TR:
css_hint_height(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_THEAD:
case DOM_HTML_ELEMENT_TYPE_TBODY:
case DOM_HTML_ELEMENT_TYPE_TFOOT:
css_hint_text_align_special(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_COL:
css_hint_vertical_align_table_cells(pw, node);
break;
case DOM_HTML_ELEMENT_TYPE_APPLET:
case DOM_HTML_ELEMENT_TYPE_IMG:
css_hint_margin_hspace_vspace(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_EMBED:
case DOM_HTML_ELEMENT_TYPE_IFRAME:
case DOM_HTML_ELEMENT_TYPE_OBJECT:
@@ -1688,7 +1688,7 @@ css_error node_presentational_hint(void *pw, void *node,
break;
case DOM_HTML_ELEMENT_TYPE_CAPTION:
css_hint_caption_side(pw, node);
- /* fall through */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE_DIV:
css_hint_text_align_special(pw, node);
break;
diff --git a/content/handlers/html/box_inspect.c b/content/handlers/html/box_inspect.c
index 181f58cf8..6591b6446 100644
--- a/content/handlers/html/box_inspect.c
+++ b/content/handlers/html/box_inspect.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <dom/dom.h>
+#include "utils/utils.h"
#include "utils/nsurl.h"
#include "utils/errors.h"
#include "netsurf/types.h"
@@ -212,7 +213,7 @@ box_move_xy(struct box *b, enum box_walk_dir dir, int *x, int *y)
rb = b;
break;
}
- /* fall through */
+ fallthrough;
case BOX_WALK_NEXT_SIBLING:
do {
diff --git a/content/handlers/html/dom_event.c b/content/handlers/html/dom_event.c
index d389a21b4..d42882515 100644
--- a/content/handlers/html/dom_event.c
+++ b/content/handlers/html/dom_event.c
@@ -25,6 +25,7 @@
#include <string.h>
#include "utils/config.h"
+#include "utils/utils.h"
#include "utils/corestrings.h"
#include "utils/nsoption.h"
#include "utils/log.h"
@@ -691,6 +692,7 @@ dom_default_action_DOMNodeInsertedIntoDocument_cb(struct dom_event *evt,
switch (tag_type) {
case DOM_HTML_ELEMENT_TYPE_SCRIPT:
dom_SCRIPT_showed_up(htmlc, (dom_html_script_element *) node);
+ fallthrough;
default:
break;
}
@@ -740,6 +742,7 @@ dom_default_action_DOMSubtreeModified_cb(struct dom_event *evt, void *pw)
case DOM_HTML_ELEMENT_TYPE_TEXTAREA:
case DOM_HTML_ELEMENT_TYPE_INPUT:
html_texty_element_update(htmlc, (dom_node *)node);
+ fallthrough;
default:
break;
}
diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c
index 9e359c98f..0a843e026 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -899,7 +899,7 @@ gadget_mouse_action(html_content *html,
}
free(oldcoords);
}
- /* Fall through */
+ fallthrough;
case GADGET_SUBMIT:
if (mas->gadget.control->form) {
@@ -1669,7 +1669,7 @@ void html_set_drag_type(html_content *html, html_drag_type drag_type,
case HTML_DRAG_SELECTION:
assert(drag_owner.no_owner == true);
- /* Fall through */
+ fallthrough;
case HTML_DRAG_TEXTAREA_SELECTION:
case HTML_DRAG_CONTENT_SELECTION:
msg_data.drag.type = CONTENT_DRAG_SELECTION;
@@ -1800,7 +1800,7 @@ void html_set_selection(html_content *html, html_selection_type selection_type,
break;
case HTML_SELECTION_SELF:
assert(selection_owner.none == false);
- /* fall through */
+ fallthrough;
case HTML_SELECTION_TEXTAREA:
case HTML_SELECTION_CONTENT:
msg_data.selection.selection = true;
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c
index 61adcaa6c..bde3c5bd1 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -960,7 +960,6 @@ static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
switch (lh__box_align_self(ctx->flex, b)) {
default:
- /* Fall through. */
case CSS_ALIGN_SELF_STRETCH:
if (lh__box_size_cross_is_auto(ctx->horizontal, b)) {
*box_size_cross += cross_free_space;
@@ -970,7 +969,7 @@ static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
return;
}
}
- /* Fall through. */
+ fallthrough;
case CSS_ALIGN_SELF_FLEX_START:
*box_pos_cross = ctx->flex->padding[cross_start] +
line->pos +
@@ -986,7 +985,6 @@ static void layout_flex__place_line_items_cross(struct flex_ctx *ctx,
break;
case CSS_ALIGN_SELF_BASELINE:
- /* Fall through. */
case CSS_ALIGN_SELF_CENTER:
*box_pos_cross = ctx->flex->padding[cross_start] +
line->pos + cross_free_space / 2 +
diff --git a/content/handlers/html/redraw_border.c b/content/handlers/html/redraw_border.c
index 39ed432cd..3a1f6f308 100644
--- a/content/handlers/html/redraw_border.c
+++ b/content/handlers/html/redraw_border.c
@@ -25,6 +25,7 @@
#include <stdbool.h>
#include <stdlib.h>
+#include "utils/utils.h"
#include "utils/log.h"
#include "netsurf/plotters.h"
#include "netsurf/css.h"
@@ -121,7 +122,7 @@ html_redraw_border_plot(const int side,
switch (style) {
case CSS_BORDER_STYLE_DOTTED:
plot_style_bdr.stroke_type = PLOT_OP_TYPE_DOT;
- /* fall through */
+ fallthrough;
case CSS_BORDER_STYLE_DASHED:
rect.x0 = (p[0] + p[2]) / 2;
rect.y0 = (p[1] + p[3]) / 2;
@@ -131,7 +132,7 @@ html_redraw_border_plot(const int side,
break;
case CSS_BORDER_STYLE_SOLID:
- /* fall through to default */
+ /* solid is the default */
default:
if (rectangular || thickness == 1) {
@@ -190,7 +191,7 @@ html_redraw_border_plot(const int side,
case CSS_BORDER_STYLE_GROOVE:
light = 3 - light;
- /* fall through */
+ fallthrough;
case CSS_BORDER_STYLE_RIDGE:
/* choose correct colours for each part of the border line */
if (light <= 1) {
@@ -300,7 +301,7 @@ html_redraw_border_plot(const int side,
case CSS_BORDER_STYLE_INSET:
light = (light + 2) % 4;
- /* fall through */
+ fallthrough;
case CSS_BORDER_STYLE_OUTSET:
/* choose correct colours for each part of the border line */
switch (light) {
diff --git a/content/handlers/html/script.c b/content/handlers/html/script.c
index 962386d68..554fc4f70 100644
--- a/content/handlers/html/script.c
+++ b/content/handlers/html/script.c
@@ -495,6 +495,7 @@ exec_src_script(html_content *c,
switch (script_type) {
case HTML_SCRIPT_SYNC:
ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
+ break;
case HTML_SCRIPT_ASYNC:
break;
diff --git a/content/handlers/html/table.c b/content/handlers/html/table.c
index 4ffcceab9..f8762e862 100644
--- a/content/handlers/html/table.c
+++ b/content/handlers/html/table.c
@@ -26,6 +26,7 @@
#include <dom/dom.h>
#include "utils/log.h"
+#include "utils/utils.h"
#include "utils/talloc.h"
#include "css/utils.h"
@@ -93,27 +94,27 @@ table_border_is_more_eyecatching(const css_unit_ctx *unit_len_ctx,
/* 3b -- sort by style */
switch (a->style) {
- case CSS_BORDER_STYLE_DOUBLE: impact++; /* Fall through */
- case CSS_BORDER_STYLE_SOLID: impact++; /* Fall through */
- case CSS_BORDER_STYLE_DASHED: impact++; /* Fall through */
- case CSS_BORDER_STYLE_DOTTED: impact++; /* Fall through */
- case CSS_BORDER_STYLE_RIDGE: impact++; /* Fall through */
- case CSS_BORDER_STYLE_OUTSET: impact++; /* Fall through */
- case CSS_BORDER_STYLE_GROOVE: impact++; /* Fall through */
- case CSS_BORDER_STYLE_INSET: impact++; /* Fall through */
+ case CSS_BORDER_STYLE_DOUBLE: impact++; fallthrough;
+ case CSS_BORDER_STYLE_SOLID: impact++; fallthrough;
+ case CSS_BORDER_STYLE_DASHED: impact++; fallthrough;
+ case CSS_BORDER_STYLE_DOTTED: impact++; fallthrough;
+ case CSS_BORDER_STYLE_RIDGE: impact++; fallthrough;
+ case CSS_BORDER_STYLE_OUTSET: impact++; fallthrough;
+ case CSS_BORDER_STYLE_GROOVE: impact++; fallthrough;
+ case CSS_BORDER_STYLE_INSET: impact++; fallthrough;
default:
break;
}
switch (b->style) {
- case CSS_BORDER_STYLE_DOUBLE: impact--; /* Fall through */
- case CSS_BORDER_STYLE_SOLID: impact--; /* Fall through */
- case CSS_BORDER_STYLE_DASHED: impact--; /* Fall through */
- case CSS_BORDER_STYLE_DOTTED: impact--; /* Fall through */
- case CSS_BORDER_STYLE_RIDGE: impact--; /* Fall through */
- case CSS_BORDER_STYLE_OUTSET: impact--; /* Fall through */
- case CSS_BORDER_STYLE_GROOVE: impact--; /* Fall through */
- case CSS_BORDER_STYLE_INSET: impact--; /* Fall through */
+ case CSS_BORDER_STYLE_DOUBLE: impact--; fallthrough;
+ case CSS_BORDER_STYLE_SOLID: impact--; fallthrough;
+ case CSS_BORDER_STYLE_DASHED: impact--; fallthrough;
+ case CSS_BORDER_STYLE_DOTTED: impact--; fallthrough;
+ case CSS_BORDER_STYLE_RIDGE: impact--; fallthrough;
+ case CSS_BORDER_STYLE_OUTSET: impact--; fallthrough;
+ case CSS_BORDER_STYLE_GROOVE: impact--; fallthrough;
+ case CSS_BORDER_STYLE_INSET: impact--; fallthrough;
default:
break;
}
@@ -128,20 +129,20 @@ table_border_is_more_eyecatching(const css_unit_ctx *unit_len_ctx,
/** \todo COL/COL_GROUP */
switch (a_src) {
- case BOX_TABLE_CELL: impact++; /* Fall through */
- case BOX_TABLE_ROW: impact++; /* Fall through */
- case BOX_TABLE_ROW_GROUP: impact++; /* Fall through */
- case BOX_TABLE: impact++; /* Fall through */
+ case BOX_TABLE_CELL: impact++; fallthrough;
+ case BOX_TABLE_ROW: impact++; fallthrough;
+ case BOX_TABLE_ROW_GROUP: impact++; fallthrough;
+ case BOX_TABLE: impact++; fallthrough;
default:
break;
}
/** \todo COL/COL_GROUP */
switch (b_src) {
- case BOX_TABLE_CELL: impact--; /* Fall through */
- case BOX_TABLE_ROW: impact--; /* Fall through */
- case BOX_TABLE_ROW_GROUP: impact--; /* Fall through */
- case BOX_TABLE: impact--; /* Fall through */
+ case BOX_TABLE_CELL: impact--; fallthrough;
+ case BOX_TABLE_ROW: impact--; fallthrough;
+ case BOX_TABLE_ROW_GROUP: impact--; fallthrough;
+ case BOX_TABLE: impact--; fallthrough;
default:
break;
}
diff --git a/content/handlers/image/webp.c b/content/handlers/image/webp.c
index da13316bc..c04c0efd2 100644
--- a/content/handlers/image/webp.c
+++ b/content/handlers/image/webp.c
@@ -142,7 +142,7 @@ webp_cache_convert(struct content *c)
default:
/* WebP has no ABGR function, fall back to default. */
webp_fmt.layout = BITMAP_LAYOUT_R8G8B8A8;
- /* Fall through. */
+ fallthrough;
case BITMAP_LAYOUT_R8G8B8A8:
decoded = WebPDecodeRGBAInto(source_data, source_size, pixels,
rowstride * webpfeatures.height, rowstride);
diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c
index c0a2749a9..a780b0067 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -385,7 +385,7 @@ static void dukky_html_element_class_from_tag_type(dom_html_element_type type,
break;
case DOM_HTML_ELEMENT_TYPE__COUNT:
assert(type != DOM_HTML_ELEMENT_TYPE__COUNT);
- /* fallthrough */
+ fallthrough;
case DOM_HTML_ELEMENT_TYPE__UNKNOWN:
SET_HTML_CLASS(UNKNOWN)
break;
diff --git a/frontends/gtk/download.c b/frontends/gtk/download.c
index 63ca1c267..d1231634d 100644
--- a/frontends/gtk/download.c
+++ b/frontends/gtk/download.c
@@ -432,7 +432,7 @@ static gboolean nsgtk_download_update(gboolean force_update)
switch (dl->status) {
case NSGTK_DOWNLOAD_WORKING:
pulse_mode = TRUE;
- /* Fall through */
+ fallthrough;
case NSGTK_DOWNLOAD_NONE:
dl->speed = dl->size_downloaded /
@@ -449,12 +449,13 @@ static gboolean nsgtk_download_update(gboolean force_update)
dl_ctx.num_active++;
update = TRUE;
- /* Fall through */
+ fallthrough;
case NSGTK_DOWNLOAD_COMPLETE:
downloaded += dl->size_downloaded;
total += dl->size_total;
dls++;
+ fallthrough;
default:
;//Do nothing
diff --git a/frontends/gtk/search.c b/frontends/gtk/search.c
index 17447bbb7..f9a509f6e 100644
--- a/frontends/gtk/search.c
+++ b/frontends/gtk/search.c
@@ -270,6 +270,8 @@ nserror nsgtk_search_restyle(struct gtk_search *search)
case 4: /* Text icons only */
gtk_toolbar_set_style(GTK_TOOLBAR(search->bar),
GTK_TOOLBAR_TEXT);
+ break;
+
default:
break;
}
diff --git a/frontends/windows/download.c b/frontends/windows/download.c
index 2b94e8363..cfd2bbbb7 100644
--- a/frontends/windows/download.c
+++ b/frontends/windows/download.c
@@ -169,7 +169,7 @@ nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
case IDOK:
if (download1->downloaded != download1->size)
return TRUE;
- /* Fall through */
+ fallthrough;
case IDCANCEL:
nsws_download_clear_data(download1);
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index 10d16deaf..00e5a7e05 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -432,7 +432,7 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
NSLOG(netsurf, INFO, "Destroyed font object");
DeleteObject(hFont);
}
- /* Fall through */
+ fallthrough;
case WM_NCDESTROY:
/* remove properties if window is being destroyed */
diff --git a/utils/utils.h b/utils/utils.h
index 3995071cd..cb9e04b45 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -89,4 +89,31 @@
*/
bool is_dir(const char *path);
+/**
+ * switch fall through
+ */
+#if defined __cplusplus && defined __has_cpp_attribute
+ #if __has_cpp_attribute(fallthrough) && __cplusplus >= __has_cpp_attribute(fallthrough)
+ #define fallthrough [[fallthrough]]
+ #elif __has_cpp_attribute(gnu::fallthrough) && __STDC_VERSION__ >= __has_cpp_attribute(gnu::fallthrough)
+ #define fallthrough [[gnu::fallthrough]]
+ #elif __has_cpp_attribute(clang::fallthrough) && __STDC_VERSION__ >= __has_cpp_attribute(clang::fallthrough)
+ #define fallthrough [[clang::fallthrough]]
+ #endif
+#elif defined __STDC_VERSION__ && defined __has_c_attribute
+ #if __has_c_attribute(fallthrough) && __STDC_VERSION__ >= __has_c_attribute(fallthrough)
+ #define fallthrough [[fallthrough]]
+ #endif
+#endif
+#if !defined fallthrough && defined __has_attribute
+ #if __has_attribute(__fallthrough__)
+ #define fallthrough __attribute__((__fallthrough__))
+ #endif
+#endif
+#if !defined fallthrough
+/* early gcc and clang have no implicit fallthrough warning */
+ #define fallthrough do {} while(0)
+#endif
+
+
#endif