Commit 80f6c19f authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[csa] Fix MSVC handling of VA_ARGS in CSA_ASSERT

MSVC's macro VA_ARGS support behaves slightly differently from
gcc/clang, where VA_ARGS is treated as a single token when passed to
other macros, e.g.

    #define FIRST(X, ...) 'X'
    #define FOO(...) FIRST(__VA_ARGS__)
    FOO(a,b,c)

expands to

    gcc/clang: 'a'
    MSVC: 'a,b,c'

The workaround to this is to wrap the call in a no-op macro, which
expands VA_ARGS first, and only then passes it through:

    #define EXPAND(x) x
    #define FOO(...) EXPAND(FIRST(__VA_ARGS__))

This was causing errors on windows builds when CSA_ASSERT was passed
multiple additional expressions.

Change-Id: Ia40bf23baf97af29c7f6f67c8a83918ecca15364
Reviewed-on: https://chromium-review.googlesource.com/586831Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46927}
parent a61fec35
......@@ -9,6 +9,8 @@
#include "src/base/format-macros.h"
#include "src/base/logging.h"
// No-op macro which is used to work around MSVC's funky VA_ARGS support.
#define EXPAND(x) x
// TODO(all) Replace all uses of this macro with C++'s offsetof. To do that, we
// have to make sure that only standard-layout types and simple field
......
......@@ -1766,9 +1766,9 @@ class ToDirectStringAssembler : public CodeStubAssembler {
// We have to jump through some hoops to allow <extra values to print...> to be
// empty.
#define CSA_ASSERT(csa, ...) \
(csa)->Assert([&] { return CSA_ASSERT_GET_CONDITION(__VA_ARGS__); }, \
CSA_ASSERT_GET_CONDITION_STR(__VA_ARGS__), __FILE__, __LINE__, \
CSA_ASSERT_STRINGIFY_EXTRA_VALUES(__VA_ARGS__))
(csa)->Assert([&] { return EXPAND(CSA_ASSERT_GET_CONDITION(__VA_ARGS__)); }, \
EXPAND(CSA_ASSERT_GET_CONDITION_STR(__VA_ARGS__)), __FILE__, \
__LINE__, CSA_ASSERT_STRINGIFY_EXTRA_VALUES(__VA_ARGS__))
#define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
(csa)->Assert( \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment