]> granicus.if.org Git - clang/commitdiff
Let NULL and MSVC headers coexist better.
authorNico Weber <nicolasweber@gmx.de>
Tue, 24 Apr 2012 21:27:01 +0000 (21:27 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 24 Apr 2012 21:27:01 +0000 (21:27 +0000)
Fixes the two issues mentioned in PR12146.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155490 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/stddef.h
test/Headers/ms-null-ms-header-vs-stddef.cpp [new file with mode: 0644]

index 9e87ee89b3b91a14d4ccd4cb7b88723d4744e986..d7db826e676e81e642a3e89ab34ac80524e30fc2 100644 (file)
@@ -43,10 +43,13 @@ typedef __WCHAR_TYPE__ wchar_t;
 
 #undef NULL
 #ifdef __cplusplus
-#undef __null  // VC++ hack.
-#define NULL __null
+#  if !defined(__MINGW32__) && !defined(_MSC_VER)
+#    define NULL __null
+#  else
+#    define NULL 0
+#  endif
 #else
-#define NULL ((void*)0)
+#  define NULL ((void*)0)
 #endif
 
 #define offsetof(t, d) __builtin_offsetof(t, d)
diff --git a/test/Headers/ms-null-ms-header-vs-stddef.cpp b/test/Headers/ms-null-ms-header-vs-stddef.cpp
new file mode 100644 (file)
index 0000000..7efa871
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang -fsyntax-only -target i686-pc-win32 %s
+// RUN: %clang -fsyntax-only -target i386-mingw32 %s
+
+// Something in MSVC's headers (pulled in e.g. by <crtdefs.h>) defines __null
+// to something, mimick that.
+#define __null
+
+#include <stddef.h>
+
+// __null is used as a type annotation in MS headers, with __null defined to
+// nothing in regular builds. This should continue to work even with stddef.h
+// included.
+void f(__null void* p) { }
+
+// NULL should work fine even with __null defined to nothing.
+void* p = NULL;