From 759cd0e86b3d4d31f81f5f567d85af6d857bb997 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 8 Oct 2015 22:25:27 +0000 Subject: [PATCH] Split out of . There are a bunch of macros (__need_size_t etc) that request just one piece of ; if any one of these is defined, we just directly include the underlying header. Note that provides a ::nullptr_t. We don't want that available to includers of , so instead of following the usual pattern where includes then pulls things from :: into std:: with using-declarations, we implement and separately; both include <__nullptr> for the definition of std::nullptr_t. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@249761 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/cstddef | 4 +- include/stddef.h | 56 +++++++++++++++++++ .../std/depr/depr.c.headers/stddef_h.pass.cpp | 22 ++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 include/stddef.h diff --git a/include/cstddef b/include/cstddef index 68f52c245..1210b9198 100644 --- a/include/cstddef +++ b/include/cstddef @@ -34,10 +34,10 @@ Types: */ #include <__config> +// Don't include our own ; we don't want to declare ::nullptr_t. +#include_next #include <__nullptr> -#include - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif diff --git a/include/stddef.h b/include/stddef.h new file mode 100644 index 000000000..6ffe58251 --- /dev/null +++ b/include/stddef.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===--------------------------- stddef.h ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#if defined(__need_ptrdiff_t) || defined(__need_size_t) || \ + defined(__need_wchar_t) || defined(__need_NULL) || defined(__need_wint_t) +#include_next + +#elif !defined(_LIBCPP_STDDEF_H) +#define _LIBCPP_STDDEF_H + +/* + stddef.h synopsis + +Macros: + + offsetof(type,member-designator) + NULL + +Types: + + ptrdiff_t + size_t + max_align_t + nullptr_t + +*/ + +#include <__config> +#include_next + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef __cplusplus + +extern "C++" { +#include <__nullptr> +using std::nullptr_t; +} + +// Re-use the compiler's max_align_t where possible. +#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) +typedef long double max_align_t; +#endif + +#endif + +#endif // _LIBCPP_STDDEF_H diff --git a/test/std/depr/depr.c.headers/stddef_h.pass.cpp b/test/std/depr/depr.c.headers/stddef_h.pass.cpp index 140c91b53..c03c314e3 100644 --- a/test/std/depr/depr.c.headers/stddef_h.pass.cpp +++ b/test/std/depr/depr.c.headers/stddef_h.pass.cpp @@ -10,6 +10,7 @@ // #include +#include #include #ifndef NULL @@ -22,6 +23,9 @@ int main() { + void *p = NULL; + assert(!p); + static_assert(sizeof(size_t) == sizeof(void*), "sizeof(size_t) == sizeof(void*)"); static_assert(std::is_unsigned::value, @@ -34,4 +38,22 @@ int main() "std::is_signed::value"); static_assert(std::is_integral::value, "std::is_integral::value"); + static_assert(std::is_same::value, + "decltype(nullptr) == nullptr_t"); + static_assert(sizeof(nullptr_t) == sizeof(void*), + "sizeof(nullptr_t) == sizeof(void*)"); + static_assert(std::is_pod::value, + "std::is_pod::value"); + static_assert((std::alignment_of::value >= + std::alignment_of::value), + "std::alignment_of::value >= " + "std::alignment_of::value"); + static_assert(std::alignment_of::value >= + std::alignment_of::value, + "std::alignment_of::value >= " + "std::alignment_of::value"); + static_assert(std::alignment_of::value >= + std::alignment_of::value, + "std::alignment_of::value >= " + "std::alignment_of::value"); }