Skip to content

Commit 5464a63

Browse files
committed
Suppress switch case fall-through warning
Since there are occasions where a switch case fall through is desirable, GCC and Clang provide an attribute, __attribute__((fallthrough)), that is to be used along with a null statement to suppress this warning that would normally occur: New macro "fallthrough" is defined according to the compilers used to build this project.
1 parent bf70e8d commit 5464a63

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

include/twin_private.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,35 @@
1212

1313
#include "twin.h"
1414

15+
/* Boilerplate for compiler compatibility */
16+
#ifndef __has_attribute
17+
#define __has_attribute(x) 0
18+
#endif
19+
20+
/* since C23 */
21+
#ifndef __has_c_attribute
22+
#define __has_c_attribute(x) 0
23+
#endif
24+
25+
#if defined(__clang__) || defined(__GNUC__)
1526
#define maybe_unused __attribute__((unused))
27+
#else
28+
#define maybe_unused
29+
#endif
30+
31+
/* suppress warnings when intentional switch case fall-through is desired. */
32+
#if defined(__has_c_attribute) && __has_c_attribute(fallthrough) /* C23+ */
33+
#define fallthrough [[fallthrough]]
34+
#elif defined(__has_attribute) && __has_attribute(fallthrough)
35+
/* GNU-style attribute. The __has_attribute() macro was first available in Clang
36+
* 2.9 and incorporated into GCC since GCC 9.
37+
*/
38+
#define fallthrough __attribute__((fallthrough))
39+
#elif defined(__GNUC__) && __GNUC__ >= 7
40+
#define fallthrough __attribute__((__fallthrough__))
41+
#else
42+
#define fallthrough ((void) 0)
43+
#endif
1644

1745
/*
1846
* Fixed-point type definitions

src/path.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void _twin_path_smove(twin_path_t *path, twin_sfixed_t x, twin_sfixed_t y)
7676
switch (_twin_current_subpath_len(path)) {
7777
default:
7878
_twin_path_sfinish(path);
79+
fallthrough;
7980
case 0:
8081
_twin_path_sdraw(path, x, y);
8182
break;

src/window.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ bool twin_window_dispatch(twin_window_t *window, twin_event_t *event)
435435
case TwinEventButtonUp:
436436
window->screen->button_x = -1;
437437
window->screen->button_y = -1;
438+
return true;
438439
case TwinEventMotion:
439440
if (window->screen->button_x >= 0) {
440441
twin_coord_t x, y;

0 commit comments

Comments
 (0)