Author: Stephen Long
Date: 2022-05-12T09:38:07-07:00
New Revision: 7f9837cfa63663ccd51da3e5de73acec8f776ee8

URL: 
https://github.com/llvm/llvm-project/commit/7f9837cfa63663ccd51da3e5de73acec8f776ee8
DIFF: 
https://github.com/llvm/llvm-project/commit/7f9837cfa63663ccd51da3e5de73acec8f776ee8.diff

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

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

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D124026

Added: 
    clang/test/Headers/ms-no-wchar.cpp

Modified: 
    clang/lib/Headers/stddef.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/stddef.h b/clang/lib/Headers/stddef.h
index 15acd4427ca14..a15d21b553174 100644
--- a/clang/lib/Headers/stddef.h
+++ b/clang/lib/Headers/stddef.h
@@ -62,7 +62,7 @@ typedef __SIZE_TYPE__ rsize_t;
 #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)

diff  --git a/clang/test/Headers/ms-no-wchar.cpp 
b/clang/test/Headers/ms-no-wchar.cpp
new file mode 100644
index 0000000000000..8fe1dbc4c87f6
--- /dev/null
+++ b/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;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to