From 46f98d86c77b1ff30b13c0a2c4f6b28bd8dd107c Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 30 Jan 2020 09:11:25 +0100 Subject: [PATCH] include: gcc.h: Add a __WARN() macro with a custom warning on expansion Works like __DEPRECATED_MACRO with a custom message. Can do this for example: #define FOO __WARN("Please use BAR instead") ... Implement __DEPRECATED_MACRO with __WARN(). Useful for https://github.com/zephyrproject-rtos/zephyr/pull/21506. Signed-off-by: Ulf Magnusson --- include/toolchain/gcc.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/toolchain/gcc.h b/include/toolchain/gcc.h index 33ad36fed78..dcaaea13dfe 100644 --- a/include/toolchain/gcc.h +++ b/include/toolchain/gcc.h @@ -206,11 +206,24 @@ do { \ #define HAS_BUILTIN___builtin_ctzll 1 #endif -/* Be *very* careful with this, you cannot filter out with -wno-deprecated, - * which has implications for -Werror +/* + * Be *very* careful with these. You cannot filter out __DEPRECATED_MACRO with + * -wno-deprecated, which has implications for -Werror. */ + +/* + * Expands to nothing and generates a warning. Used like + * + * #define FOO __WARN("Please use BAR instead") ... + * + * The warning points to the location where the macro is expanded. + */ +#define __WARN(msg) __WARN1(GCC warning msg) +#define __WARN1(s) _Pragma(#s) + +/* Generic message */ #ifndef __DEPRECATED_MACRO -#define __DEPRECATED_MACRO _Pragma("GCC warning \"Macro is deprecated\"") +#define __DEPRECATED_MACRO __WARN("Macro is deprecated") #endif /* These macros allow having ARM asm functions callable from thumb */