From 6966d7ea0821969ed4f2449fafd1197141e4bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 26 Feb 2021 15:36:42 +0100 Subject: [PATCH] widl: Fix C++ RuntimeClass string constants declaration. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MinGW g++ requires initialized selectany to have extern linkage. Also, because of the various ways WCHAR may be defined, using an array initializer is the simplest way to support all cases. Signed-off-by: RĂ©mi Bernon Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- tools/widl/header.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/widl/header.c b/tools/widl/header.c index a472af49066..cb0dc2f43a3 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1835,11 +1835,15 @@ static void write_runtimeclass(FILE *header, type_t *runtimeclass) if (contract) write_apicontract_guard_start(header, contract); fprintf(header, "#ifndef RUNTIMECLASS_%s_DEFINED\n", c_name); fprintf(header, "#define RUNTIMECLASS_%s_DEFINED\n", c_name); - fprintf(header, "#if defined(_MSC_VER) || defined(__MINGW32__)\n"); + fprintf(header, "#if !defined(_MSC_VER) && !defined(__MINGW32__)\n"); + fprintf(header, "static const WCHAR RuntimeClass_%s[] = {", c_name); + for (i = 0, len = strlen(name); i < len; ++i) fprintf(header, "'%c',", name[i]); + fprintf(header, "0};\n"); + fprintf(header, "#elif defined(__GNUC__) && !defined(__cplusplus)\n"); /* FIXME: MIDL generates extern const here but GCC warns if extern is initialized */ fprintf(header, "const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = L\"%s\";\n", c_name, name); fprintf(header, "#else\n"); - fprintf(header, "static const WCHAR RuntimeClass_%s[] = {", c_name); + fprintf(header, "extern const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = {", c_name); for (i = 0, len = strlen(name); i < len; ++i) fprintf(header, "'%c',", name[i]); fprintf(header, "0};\n"); fprintf(header, "#endif\n");