[PATCH] D124026: [Headers][MSVC] Define wchar_t in stddef.h like MSVC if not using the builtin type

Stephen Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 19 11:11:02 PDT 2022


steplong created this revision.
steplong added reviewers: rnk, efriedma.
Herald added a project: All.
steplong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

MSVC expects wchar_t to be defined in stddef.h if /Zc:wchar_t- is specified


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124026

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/ms-no-wchar.cpp


Index: clang/test/Headers/ms-no-wchar.cpp
===================================================================
--- /dev/null
+++ clang/test/Headers/ms-no-wchar.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-windows-msvc -fms-compatibility-version=17.00 -fno-wchar %s
+// MSVC defines wchar_t instead of using the builtin if /Zc:wchar_t- is passed
+
+#include <stddef.h>
+
+wchar_t c;
Index: clang/lib/Headers/stddef.h
===================================================================
--- clang/lib/Headers/stddef.h
+++ clang/lib/Headers/stddef.h
@@ -62,7 +62,7 @@
 #endif /* defined(__need_STDDEF_H_misc) */
 
 #if defined(__need_wchar_t)
-#ifndef __cplusplus
+#if !defined(__cplusplus) || (defined(_MSC_VER) && !_NATIVE_WCHAR_T_DEFINED)
 /* Always define wchar_t when modules are available. */
 #if !defined(_WCHAR_T) || __has_feature(modules)
 #if !__has_feature(modules)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124026.423678.patch
Type: text/x-patch
Size: 900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220419/eff63bf1/attachment.bin>


More information about the cfe-commits mailing list