[Git][NTPsec/ntpsec][master] 3 commits: include/ntp_types.h: define FALLTHRU wherever the attribute exists
Gary E. Miller (@garyedmundsmiller)
gitlab at mg.gitlab.com
Tue Nov 3 22:00:42 UTC 2026
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
862bd528 by Matt Selsky at 2026-11-03T02:39:56-05:00
include/ntp_types.h: define FALLTHRU wherever the attribute exists
FALLTHRU expanded to nothing on clang, so clang would warn on every
annotated fall-through once -Wimplicit-fallthrough is enabled for it.
Emit __attribute__((fallthrough)) whenever __has_attribute reports it,
which covers gcc 7+ and clang 10+.
Move the macro from ntpd.h to ntp_types.h so code outside ntpd, such
as libparse and ntpfrob, can use it; ntpd.h still gets it through
ntp.h.
- - - - -
7e0fa47e by Matt Selsky at 2026-11-03T02:39:56-05:00
Mark intentional fall-throughs with FALLTHRU
gcc's -Wimplicit-fallthrough=3 accepts a fall-through comment, but
clang only honors the attribute. Replace the comment-only annotations
that clang flags, and add the missing one in refclock_truetime.c, so
clang -Wimplicit-fallthrough is quiet.
- - - - -
3f121c74 by Matt Selsky at 2026-11-03T02:39:56-05:00
wscript: enable -Wimplicit-fallthrough on clang too
clang does not know -Wimplicit-fallthrough=3. With --enable-Werror the
configure check fails; without it, clang warns about an unknown option
on every compile. Either way clang builds had no fall-through
warnings. Plain -Wimplicit-fallthrough is level 3 on gcc and is
accepted by clang.
- - - - -
9 changed files:
- include/ntp_types.h
- include/ntpd.h
- libparse/clk_trimtsip.c
- ntpd/ntp_loopfilter.c
- ntpd/nts_server.c
- ntpd/refclock_gpsd.c
- ntpd/refclock_truetime.c
- ntpfrob/main.c
- wscript
Changes:
=====================================
include/ntp_types.h
=====================================
@@ -123,5 +123,16 @@ typedef int SOCKET;
# define INVALID_SOCKET (-1)
# define SOCKET_ERROR (-1)
+/*
+ * macro to silence -Wimplicit-fallthrough
+ */
+#if defined __has_attribute
+# if __has_attribute(fallthrough)
+# define FALLTHRU __attribute__ ((fallthrough));
+# endif
+#endif
+#ifndef FALLTHRU
+# define FALLTHRU
+#endif
#endif /* GUARD_NTP_TYPES_H */
=====================================
include/ntpd.h
=====================================
@@ -25,18 +25,6 @@
* -----------------------------------------
*/
-/*
- * macro to silence -Wimplicit-fallthrough
- * of course gcc and clang do it differently
- */
-#ifdef __clang__
-# define FALLTHRU
-#elif defined __GNUC__ && (6 < __GNUC__ )
-# define FALLTHRU __attribute__ ((fallthrough));
-#else
-# define FALLTHRU
-#endif
-
/* ntpd.c */
extern void announce_starting(void);
=====================================
libparse/clk_trimtsip.c
=====================================
@@ -155,7 +155,7 @@ inp_tsip(
t->t_in_pkt = t->t_dle = 0;
return PARSE_INP_TIME|PARSE_INP_DATA;
}
- /*FALLTHROUGH*/
+ FALLTHRU
default: /* collect data */
t->t_dle = 0;
=====================================
ntpd/ntp_loopfilter.c
=====================================
@@ -657,7 +657,7 @@ local_clock(
}
clock_frequency = direct_freq(fp_offset);
- /* fall through */
+ FALLTHRU
/*
* We get here by default in FSET, SPIK and SYNC states.
=====================================
ntpd/nts_server.c
=====================================
@@ -336,7 +336,7 @@ void nts_ke_accept_fail(NTS_Server_Info *nsi,
msg = "Connection reset";
break;
}
- // fall through
+ FALLTHRU
default:
ntp_strerror_r(errno, nsi->errbuf, sizeof(nsi->errbuf));
snprintf(buff, sizeof(buff), "code %d, errno=>%d, %s",
=====================================
ntpd/refclock_gpsd.c
=====================================
@@ -1176,7 +1176,7 @@ json_token_skip(
switch (ctx->tok[tid].type) {
case JSMN_OBJECT:
len *= 2;
- /* FALLTHROUGH */
+ FALLTHRU
case JSMN_ARRAY:
for (++tid; len; --len)
tid = json_token_skip(ctx, tid);
=====================================
ntpd/refclock_truetime.c
=====================================
@@ -691,6 +691,7 @@ true_doevent(
case s_Max:
msyslog(LOG_INFO, "REFCLOCK: TRUETIME: state %s is unexpected!",
stateStr(up->state));
+ FALLTHRU
default:
// huh?
break;
=====================================
ntpfrob/main.c
=====================================
@@ -107,7 +107,7 @@ main(int argc, char **argv)
exit(0);
default:
fputs("ntpfrob: no mode option specified.\n", stderr);
- /* fall through */
+ FALLTHRU
case 'h':
case '?':
usage();
=====================================
wscript
=====================================
@@ -371,7 +371,7 @@ def configure(ctx):
"-Wswitch-enum", # warns on missing enum case handler
] + ctx.env.CFLAGS
cc_test_flags += [
- ('w_implicit_fallthru', "-Wimplicit-fallthrough=3"),
+ ('w_implicit_fallthru', "-Wimplicit-fallthrough"),
# Fails on Solaris, OpenBSD 6, and RasPi
# Complains about a Bison bug
# Cannot be suppressed
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/097ea276d9e1b860aac548830a8bc03f1ceb6889...3f121c74c17c5b74b99284827ba21dc9131a9e77
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/097ea276d9e1b860aac548830a8bc03f1ceb6889...3f121c74c17c5b74b99284827ba21dc9131a9e77
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20261103/c82ab5b8/attachment-0001.htm>
More information about the vc
mailing list