C99 inline functions are useful whenever a function provide an abstraction that is generally expected to be inlined away, but yet a function pointer might be needed. One such case is function passed to GCC's cleanup attribute.
Unfortunately, C99 inline functions clash a bit with -Wredundant-decls. Provide a helper macro to hide the ugliness. Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- include/qemu/compiler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 340e5fdc09..e02b73b9e2 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -94,6 +94,21 @@ #define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \ sizeof(QEMU_BUILD_BUG_ON_STRUCT(x))) +/* Provide an extern declaration for a C99 inline function. This can + * be simply placed in a C file but, unfortunately, this means the + * declaration comes after the inline definition, and GCC thus + * stubbornly raises a -Wredundant-decls warning. + * + * Putting the declaration before the header would be uglier (it couldn't + * just use typeof) and not always possible if the function requires types + * that are defined in the header. Therefore, we just shut up the warning. + */ +#define QEMU_EXTERN_INLINE(func) \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wredundant-decls\""); \ + extern typeof(func) func; \ + _Pragma("GCC diagnostic pop") \ + #if defined __GNUC__ # if !QEMU_GNUC_PREREQ(4, 4) /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */ -- 2.14.3