diff options
author | Nico Weber <nicolasweber@gmx.de> | 2012-04-24 21:27:01 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2012-04-24 21:27:01 +0000 |
commit | 1d725ecf93037e8877286f53a7289f39064a9fc5 (patch) | |
tree | 7eb0aad6461a68499a4b1cc213d11a0ab8c85443 | |
parent | a8022fa70de20171d95d54d6921d7a32d7108a77 (diff) | |
download | bcm5719-llvm-1d725ecf93037e8877286f53a7289f39064a9fc5.tar.gz bcm5719-llvm-1d725ecf93037e8877286f53a7289f39064a9fc5.zip |
Let NULL and MSVC headers coexist better.
Fixes the two issues mentioned in PR12146.
llvm-svn: 155490
-rw-r--r-- | clang/lib/Headers/stddef.h | 9 | ||||
-rw-r--r-- | clang/test/Headers/ms-null-ms-header-vs-stddef.cpp | 16 |
2 files changed, 22 insertions, 3 deletions
diff --git a/clang/lib/Headers/stddef.h b/clang/lib/Headers/stddef.h index 9e87ee89b3b..d7db826e676 100644 --- a/clang/lib/Headers/stddef.h +++ b/clang/lib/Headers/stddef.h @@ -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/clang/test/Headers/ms-null-ms-header-vs-stddef.cpp b/clang/test/Headers/ms-null-ms-header-vs-stddef.cpp new file mode 100644 index 00000000000..7efa871da90 --- /dev/null +++ b/clang/test/Headers/ms-null-ms-header-vs-stddef.cpp @@ -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; |