diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-04-27 20:23:54 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-04-27 20:26:17 +0200 |
commit | eb7f23d1c95c4f435a6bc808bbef9e05c551b8eb (patch) | |
tree | ba809d40da97b0ac245f026b85b2dfabb13df158 /compat | |
parent | e36b3c4919a703b20838fa3c23456326b9d84b72 (diff) |
compat/macros: add static_warning macro
Diffstat (limited to 'compat')
-rw-r--r-- | compat/macros.hpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/compat/macros.hpp b/compat/macros.hpp index b0c7a51d..c0bc66f4 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -47,5 +47,43 @@ #endif #if defined __cplusplus + +// from now only C++ macros + # define thunk(...) ([&]() { __VA_ARGS__; }) + +#if defined _MSC_VER +# define OTR_DEPRECATE(msg, decl, body) __declspec(deprecated(msg)) decl body +#else +# define OTR_DEPRECATE(msg, decl, body) decl body __attribute__((deprecated(msg))) +#endif + +#if !defined PP_CAT +# define PP_CAT(x,y) PP_CAT1(x,y) +# define PP_CAT1(x,y) x##y +#endif + +namespace static_warning_detail { + template<bool> struct test___132; + + template<> + struct test___132<true> + { + static constexpr inline void check() {} + }; +} // ns static_warning_detail + +#define static_warning_template(cond, msg) \ + { \ + template<bool> \ + struct ::static_warning_detail::test___132 \ + { \ + OTR_DEPRECATE(msg, static constexpr inline void check(), {}) \ + }; \ + ::static_warning_detail::test___132<(cond)>::check(); \ + } + +#define static_warning(cond, msg) \ + static_warning_template(cond, PP_CAT(msg, PP_CAT("\nExpression: ", #cond))) + #endif |