Skip to content

Commit c5dacad

Browse files
authored
[Bugfix] Handle gcc unsupported __VA_OPT___ macro (#1881)
Add check to see if `__VA_OPT__` macro is supported, if not, applies `<true_result>` value for `COND()` macro by default. This has the side-effect/limitation that all protocol names are included in the build, even if the protocol is not available in the code, but _only_ for compilers dat do _not_ support the `__VA_OPT__` macro, notably gcc 4.8.2 (and older). Resolves #1880
1 parent 84f596e commit c5dacad

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/IRmacros.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
*/
66
/// @file IRmacros.h
77

8+
/**
9+
* VA_OPT_SUPPORTED macro to check if __VA_OPT__ is supported
10+
* Source: https://stackoverflow.com/a/48045656
11+
*/
12+
/// @cond TEST
13+
#define PP_THIRD_ARG(a, b, c, ...) c
14+
#define VA_OPT_SUPPORTED_I(...) \
15+
PP_THIRD_ARG(__VA_OPT__(, false), true, false, false)
16+
#define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?)
17+
/// @endcond
18+
/**
19+
* VA_OPT_SUPPORTED end
20+
*/
21+
822
/**
923
* COND() Set of macros to facilitate single-line conditional compilation
1024
* argument checking.
@@ -13,8 +27,14 @@
1327
*
1428
* Usage:
1529
* COND(<define_to_test>[||/&&<more_define>...], <true_result>, <false_result>)
30+
*
31+
* NB: If __VA_OPT__ macro not supported, the <true_result> will be expanded!
1632
*/
1733
/// @cond TEST
34+
#if !VA_OPT_SUPPORTED
35+
// #pragma message("Compiler without __VA_OPT__ support")
36+
#define COND(cond, a, b) a
37+
#else // !VA_OPT_SUPPORTED
1838
#define NOTHING
1939
#define EXPAND(...) __VA_ARGS__
2040
#define STUFF_P(a, ...) __VA_OPT__(a)
@@ -24,6 +44,7 @@
2444
#define NEGATE(a) VA_TEST(a, a)
2545
#define COND_P(cond, a, b) STUFF(a, cond)STUFF(b, NEGATE(cond))
2646
#define COND(cond, a, b) EXPAND(COND_P(cond, a, b))
47+
#endif // !VA_OPT_SUPPORTED
2748
/// @endcond
2849
/**
2950
* end of COND() set of macros

0 commit comments

Comments
 (0)