Skip to content

Commit

Permalink
Work around another MSVC bug with variadic macros.
Browse files Browse the repository at this point in the history
Bug: b/129259232
Change-Id: I095618a97edd5d4e8e28b90dd8f329b140aaa248
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27785
Presubmit-Ready: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
  • Loading branch information
ben-clayton committed Mar 25, 2019
1 parent e24bc66 commit 221459f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Reactor/Reactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,11 @@ namespace rr
// See: https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/preprocessor/macros/__VA_ARGS__/count-arguments
// Note, this doesn't attempt to use the ##__VA_ARGS__ trick to handle 0
// args as this appears to still be broken on certain compilers.
#define RR_GET_NTH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N
// MSVC also has issues with variadic macros which requires the RR_VA_MSVC_BUG() work-around.
// See: https://stackoverflow.com/a/48711060
#define RR_VA_MSVC_BUG(MACRO, ARGS) MACRO ARGS
#define RR_GET_NTH_ARG_EX(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N
#define RR_GET_NTH_ARG(...) RR_VA_MSVC_BUG(RR_GET_NTH_ARG_EX, (__VA_ARGS__))
#define RR_COUNT_ARGUMENTS(...) RR_GET_NTH_ARG(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
static_assert(1 == RR_COUNT_ARGUMENTS(a), "RR_COUNT_ARGUMENTS broken"); // Sanity checks.
static_assert(2 == RR_COUNT_ARGUMENTS(a, b), "RR_COUNT_ARGUMENTS broken");
Expand Down

0 comments on commit 221459f

Please sign in to comment.