Skip to content

Commit

Permalink
compilersupport_p.h: add a macro for the fallthrough attribute
Browse files Browse the repository at this point in the history
The /* fallthrough */ comment isn't always handled, causing some
compilers to complain about falling through.

Signed-off-by: Thiago Macieira <[email protected]>
  • Loading branch information
thiagomacieira committed Feb 7, 2025
1 parent 1bcde87 commit ef1cb5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cborparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static CborError preparse_value(CborValue *it)
case SinglePrecisionFloat:
case DoublePrecisionFloat:
it->flags |= CborIteratorFlag_IntegerValueTooLarge;
/* fall through */
CBOR_FALLTHROUGH;
case TrueValue:
case NullValue:
case UndefinedValue:
Expand Down
14 changes: 14 additions & 0 deletions src/compilersupport_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@
#else
# define cbor_static_assert(x) ((void)sizeof(char[2*!!(x) - 1]))
#endif

#if defined(__has_cpp_attribute) // C23 and C++17
# if __has_cpp_attribute(fallthrough)
# define CBOR_FALLTHROUGH [[fallthrough]]
# endif
#endif
#ifndef CBOR_FALLTHROUGH
# ifdef __GNUC__
# define CBOR_FALLTHROUGH __attribute__((fallthrough))
# else
# define CBOR_FALLTHROUGH do { } while (0)
# endif
#endif

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus)
/* inline is a keyword */
#else
Expand Down

0 comments on commit ef1cb5a

Please sign in to comment.