From d2016469064bdb488ce271c84684518d2716fec2 Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Mon, 16 Dec 2019 11:23:21 -0500 Subject: Workaround VS bug w.r.t empty arguments to macros Empty arguments can be passed to macros per C99 and C++11 specs, which can then be forwarded to other macros. Visual Studio's compiler has a bug in the following situation: #define A(x) #x #define B(x, y) A(x) B(, b) In the above case, Visual Studio first expands x to nothing, then complains that A is not invoked with the right amount of arguments. However, x in A(x) is still one argument, even if it expands to no preprocessing tokens. See also https://stackoverflow.com/a/7674214. --- googletest/include/gtest/internal/gtest-internal.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index eac831a..978728e 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -79,7 +79,16 @@ #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar // Stringifies its argument. -#define GTEST_STRINGIFY_(name) #name +// Work around a bug in visual studio which doesn't accept code like this: +// +// #define GTEST_STRINGIFY_(name) #name +// #define MACRO(a, b, c) ... GTEST_STRINGIFY_(a) ... +// MACRO(, x, y) +// +// Complaining about the argument to GTEST_STRINGIFY_ being empty. +// This is allowed by the spec. +#define GTEST_STRINGIFY_HELPER_(name, ...) #name +#define GTEST_STRINGIFY_(...) GTEST_STRINGIFY_HELPER_(__VA_ARGS__,) namespace proto2 { class Message; } -- cgit v0.12