From: "Rémi Bernon" Subject: Re: [PATCH v2] widl: Fix C++ RuntimeClass string constants declaration. Message-Id: <54dc797f-0ea8-761b-e56c-1bd2fa15d5dc@codeweavers.com> Date: Fri, 26 Feb 2021 09:53:29 +0100 In-Reply-To: <20210226084710.2785409-1-rbernon@codeweavers.com> References: <20210226084306.2784145-1-rbernon@codeweavers.com> <20210226084710.2785409-1-rbernon@codeweavers.com> On 2/26/21 9:47 AM, Rémi Bernon wrote: > MinGW g++ requires initialized selectany to have extern linkage. > > When supported, we define WCHAR as char16_t, which requires u"" string > literal. When not supported, and when WCHAR is unsigned short, it then > requires to use an array initializer instead of a L"" string literal. > > Signed-off-by: Rémi Bernon > --- > tools/widl/header.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/tools/widl/header.c b/tools/widl/header.c > index a472af49066..8993038baca 100644 > --- a/tools/widl/header.c > +++ b/tools/widl/header.c > @@ -1836,8 +1836,18 @@ static void write_runtimeclass(FILE *header, type_t *runtimeclass) > 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, "#ifdef __cplusplus\n"); > + fprintf(header, "#if defined(WINE_UNICODE_NATIVE)\n"); > + fprintf(header, "extern const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = L\"%s\";\n", c_name, name); > + fprintf(header, "#else\n"); > + 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"); > + fprintf(header, "#else /* __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, "#endif\n"); > fprintf(header, "#else\n"); > fprintf(header, "static const WCHAR RuntimeClass_%s[] = {", c_name); > for (i = 0, len = strlen(name); i < len; ++i) fprintf(header, "'%c',", name[i]); > The commit comment is also a bit inaccurate too now, as I late folded the u"" string literal case with the array initializer, trying to keep things simple... Sorry. Not sure if it's worth another version, the details could probably be cut, just tell me. -- Rémi Bernon