Skip to content

Commit 8327d0d

Browse files
committed
test: Use explicit switch fall-through annotations for long-double
Borrow the picolibc fall-through annotations so that this file doesn't depend on being built with picolibc. Signed-off-by: Keith Packard <[email protected]>
1 parent 9518980 commit 8327d0d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

test/long_double.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@
4141
#include <stdlib.h>
4242
#include <string.h>
4343

44+
/*
45+
* fall-through case statement annotations
46+
*/
47+
#if __cplusplus >= 201703L || __STDC_VERSION__ > 201710L
48+
/* Standard C++17/C23 attribute */
49+
#define __TEST_PICOLIBC_FALLTHROUGH [[fallthrough]]
50+
#elif __has_attribute(fallthrough)
51+
/* Non-standard but supported by at least gcc and clang */
52+
#define __TEST_PICOLIBC_FALLTHROUGH __attribute__((fallthrough))
53+
#else
54+
#define __TEST_PICOLIBC_FALLTHROUGH do { } while(0)
55+
#endif
56+
4457
#ifdef _TEST_LONG_DOUBLE
4558

4659
static long double max_error;
@@ -267,15 +280,14 @@ naive_strtold(const char *buf)
267280
}
268281
return -(long double)INFINITY;
269282
}
270-
/* FALLTHROUGH */
271283
if (base == 10.0L) {
272284
if (state == LDOUBLE_INT || state == LDOUBLE_FRAC) {
273285
state = LDOUBLE_EXP;
274286
continue;
275287
}
276288
return -(long double)INFINITY;
277289
}
278-
/* FALLTHROUGH */
290+
__TEST_PICOLIBC_FALLTHROUGH;
279291
case 'A': case 'B': case 'C':
280292
case 'D': case 'F':
281293
if (state == LDOUBLE_INT || state == LDOUBLE_FRAC) {
@@ -291,7 +303,7 @@ naive_strtold(const char *buf)
291303
}
292304
return -(long double)INFINITY;
293305
}
294-
/* FALLTHROUGH */
306+
__TEST_PICOLIBC_FALLTHROUGH;
295307
case 'a': case 'b': case 'c':
296308
case 'd': case 'f':
297309
if (state == LDOUBLE_INT || state == LDOUBLE_FRAC) {

0 commit comments

Comments
 (0)