Commit 2f2f9759 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

Remove msvc preprocessor compat hacks from export_template.h

Bug: 1053958
Change-Id: I07aeae7ebbd5259e030dfad7f1792b44a49b8fc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063905Reviewed-by: default avatarHans Wennborg <hans@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742624}
parent bd02aad0
......@@ -40,61 +40,33 @@
//
// The implementation of this header uses some subtle macro semantics to
// detect what the provided FOO_EXPORT value was defined as and then
// to dispatch to appropriate macro definitions. Unfortunately,
// MSVC's C preprocessor is rather non-compliant and requires special
// care to make it work.
//
// Issue 1.
//
// #define F(x)
// F()
//
// MSVC emits warning C4003 ("not enough actual parameters for macro
// 'F'), even though it's a valid macro invocation. This affects the
// macros below that take just an "export" parameter, because export
// may be empty.
//
// As a workaround, we can add a dummy parameter and arguments:
//
// #define F(x,_)
// F(,)
//
// Issue 2.
//
// #define F(x) G##x
// #define Gj() ok
// F(j())
//
// The correct replacement for "F(j())" is "ok", but MSVC replaces it
// with "Gj()". As a workaround, we can pass the result to an
// identity macro to force MSVC to look for replacements again. (This
// is why EXPORT_TEMPLATE_STYLE_3 exists.)
// to dispatch to appropriate macro definitions.
#define EXPORT_TEMPLATE_DECLARE(export) \
EXPORT_TEMPLATE_INVOKE(DECLARE, EXPORT_TEMPLATE_STYLE(export, ), export)
EXPORT_TEMPLATE_INVOKE(DECLARE, EXPORT_TEMPLATE_STYLE(export), export)
#define EXPORT_TEMPLATE_DEFINE(export) \
EXPORT_TEMPLATE_INVOKE(DEFINE, EXPORT_TEMPLATE_STYLE(export, ), export)
EXPORT_TEMPLATE_INVOKE(DEFINE, EXPORT_TEMPLATE_STYLE(export), export)
// INVOKE is an internal helper macro to perform parameter replacements
// and token pasting to chain invoke another macro. E.g.,
// EXPORT_TEMPLATE_INVOKE(DECLARE, DEFAULT, FOO_EXPORT)
// will export to call
// EXPORT_TEMPLATE_DECLARE_DEFAULT(FOO_EXPORT, )
// EXPORT_TEMPLATE_DECLARE_DEFAULT(FOO_EXPORT)
// (but with FOO_EXPORT expanded too).
#define EXPORT_TEMPLATE_INVOKE(which, style, export) \
EXPORT_TEMPLATE_INVOKE_2(which, style, export)
#define EXPORT_TEMPLATE_INVOKE_2(which, style, export) \
EXPORT_TEMPLATE_##which##_##style(export, )
EXPORT_TEMPLATE_##which##_##style(export)
// Default style is to apply the FOO_EXPORT macro at declaration sites.
#define EXPORT_TEMPLATE_DECLARE_DEFAULT(export, _) export
#define EXPORT_TEMPLATE_DEFINE_DEFAULT(export, _)
#define EXPORT_TEMPLATE_DECLARE_DEFAULT(export) export
#define EXPORT_TEMPLATE_DEFINE_DEFAULT(export)
// The "MSVC hack" style is used when FOO_EXPORT is defined
// as __declspec(dllexport), which MSVC requires to be used at
// definition sites instead.
#define EXPORT_TEMPLATE_DECLARE_MSVC_HACK(export, _)
#define EXPORT_TEMPLATE_DEFINE_MSVC_HACK(export, _) export
#define EXPORT_TEMPLATE_DECLARE_MSVC_HACK(export)
#define EXPORT_TEMPLATE_DEFINE_MSVC_HACK(export) export
// EXPORT_TEMPLATE_STYLE is an internal helper macro that identifies which
// export style needs to be used for the provided FOO_EXPORT macro definition.
......@@ -105,17 +77,14 @@
// __declspec annotations into macro invocations. E.g., if FOO_EXPORT is
// defined as "__declspec(dllimport)", it undergoes the following sequence of
// macro substitutions:
// EXPORT_TEMPLATE_STYLE(FOO_EXPORT, )
// EXPORT_TEMPLATE_STYLE_2(__declspec(dllimport), )
// EXPORT_TEMPLATE_STYLE_3(EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport))
// EXPORT_TEMPLATE_STYLE(FOO_EXPORT)
// EXPORT_TEMPLATE_STYLE_2(__declspec(dllimport))
// EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport)
// EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport
// DEFAULT
#define EXPORT_TEMPLATE_STYLE(export, _) EXPORT_TEMPLATE_STYLE_2(export, )
#define EXPORT_TEMPLATE_STYLE_2(export, _) \
EXPORT_TEMPLATE_STYLE_3( \
EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA##export)
#define EXPORT_TEMPLATE_STYLE_3(style) style
#define EXPORT_TEMPLATE_STYLE(export) EXPORT_TEMPLATE_STYLE_2(export)
#define EXPORT_TEMPLATE_STYLE_2(export) \
EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA##export
// Internal helper macros for EXPORT_TEMPLATE_STYLE.
//
......@@ -144,7 +113,7 @@
// EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport));
//
// static_assert(EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT,
// EXPORT_TEMPLATE_STYLE(__declspec(dllimport), ),
// EXPORT_TEMPLATE_STYLE(__declspec(dllimport)),
// __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT,
......@@ -157,8 +126,8 @@
//
// When they're not working correctly, a syntax error should occur instead.
#define EXPORT_TEMPLATE_TEST(want, export) \
static_assert(EXPORT_TEMPLATE_INVOKE( \
TEST_##want, EXPORT_TEMPLATE_STYLE(export, ), export), \
static_assert(EXPORT_TEMPLATE_INVOKE(TEST_##want, \
EXPORT_TEMPLATE_STYLE(export), export), \
#export)
#define EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(...) true
#define EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK(...) true
......
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