From: "Rémi Bernon" Subject: [PATCH v3] widl: Fix C++ RuntimeClass string constants declaration. Message-Id: <20210226143642.3480427-1-rbernon@codeweavers.com> Date: Fri, 26 Feb 2021 15:36:42 +0100 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 --- As suggested, reduce the number of cases here and use array initializer in C++. 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 bea5da124a4..16c8b57fd6e 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1880,11 +1880,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"); -- 2.30.0