Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Handle gcc unsupported __VA_OPT___ macro (#1880) #1881

23 changes: 23 additions & 0 deletions src/IRmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
*/
/// @file IRmacros.h

/**
* VA_OPT_SUPPORTED macro to check if __VA_OPT__ is supported
* Source: https://stackoverflow.com/questions/48045470/
tonhuisman marked this conversation as resolved.
Show resolved Hide resolved
* portably-detect-va-opt-support
* (answer by cpplearner)
*/
/// @cond TEST
#define PP_THIRD_ARG(a, b, c, ...) c
#define VA_OPT_SUPPORTED_I(...) \
PP_THIRD_ARG(__VA_OPT__(, false), true, false, false)
#define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?)
/// @endcond
/**
* VA_OPT_SUPPORTED end
*/

/**
* COND() Set of macros to facilitate single-line conditional compilation
* argument checking.
Expand All @@ -13,8 +29,14 @@
*
* Usage:
* COND(<define_to_test>[||/&&<more_define>...], <true_result>, <false_result>)
*
* NB: If __VA_OPT__ macro not supported, the <true_result> will be expanded!
*/
/// @cond TEST
#if !VA_OPT_SUPPORTED
// #pragma message("Compiler without __VA_OPT__ support")
#define COND(cond, a, b) a
#else
#define NOTHING
#define EXPAND(...) __VA_ARGS__
#define STUFF_P(a, ...) __VA_OPT__(a)
Expand All @@ -24,6 +46,7 @@
#define NEGATE(a) VA_TEST(a, a)
#define COND_P(cond, a, b) STUFF(a, cond)STUFF(b, NEGATE(cond))
#define COND(cond, a, b) EXPAND(COND_P(cond, a, b))
#endif
/// @endcond
/**
* end of COND() set of macros
Expand Down