[PATCH 1/4] widl: Fix C++ RuntimeClass string constants declaration.

Rémi Bernon rbernon at codeweavers.com
Fri Feb 26 02:43:03 CST 2021


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 <rbernon at codeweavers.com>
---
 tools/widl/header.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index a472af49066..23de3e12aca 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 /* __cplusplus */\n");
+    fprintf(header, "#else\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]);
-- 
2.30.0




More information about the wine-devel mailing list