Define SPA_FALLTHROUGH to make fall-through annotations work for all compilers

This is needed for example for Clang compiler which uses different
annotations than GCC. It will make WebRTC to happily use PipeWire
since the spa library is header-only and WebRTC defaults to use
Clang with -Wimplicit-fallthrough.
This commit is contained in:
Jan Grulich 2020-10-13 09:58:43 +02:00 committed by Wim Taymans
parent 406b99c4c5
commit 743cf58fb7
17 changed files with 73 additions and 46 deletions

View file

@ -587,6 +587,7 @@ spa_pod_builder_addv(struct spa_pod_builder *builder, va_list args)
if (type == 0)
goto exit;
spa_pod_builder_control(builder, offset, type);
SPA_FALLTHROUGH
}
default:
break;

View file

@ -420,11 +420,11 @@ do { \
case 'a': \
va_arg(args, void*); \
va_arg(args, void*); \
/* fallthrough */ \
SPA_FALLTHROUGH \
case 'p': \
case 'y': \
va_arg(args, void*); \
/* fallthrough */ \
SPA_FALLTHROUGH \
case 'b': \
case 'I': \
case 'i': \

View file

@ -36,6 +36,30 @@ extern "C" {
#include <stddef.h>
#include <stdio.h>
/**
* SPA_FALLTHROUGH is an annotation to suppress compiler warnings about switch
* cases that fall through without a break or return statement. SPA_FALLTHROUGH
* is only needed on cases that have code:
*
* switch (foo) {
* case 1: // These cases have no code. No fallthrough annotations are needed.
* case 2:
* case 3:
* foo = 4; // This case has code, so a fallthrough annotation is needed:
* SPA_FALLTHROUGH;
* default:
* return foo;
* }
*/
#if defined(__clang__) && __cplusplus >= 201103L
/* clang's fallthrough annotations are only available starting in C++11. */
# define SPA_FALLTHROUGH [[clang::fallthrough]];
#elif defined(__GNUC__) && __GNUC__ >= 7
#define SPA_FALLTHROUGH __attribute__ ((fallthrough));
#else
# define SPA_FALLTHROUGH /* FALLTHROUGH */
#endif
#define SPA_FLAG_MASK(field,mask,flag) (((field) & (mask)) == (flag))
#define SPA_FLAG_IS_SET(field,flag) SPA_FLAG_MASK(field,flag,flag)
#define SPA_FLAG_SET(field,flag) ((field) |= (flag))