Split <stddef.h> out of <cstddef>.
There are a bunch of macros (__need_size_t etc) that request just one piece of <stddef.h>; if any one of these is defined, we just directly include the underlying header. Note that <stddef.h> provides a ::nullptr_t. We don't want that available to includers of <cstddef>, so instead of following the usual pattern where <cfoo> includes <foo.h> then pulls things from :: into std:: with using-declarations, we implement <stddef.h> and <cstddef> 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
This commit is contained in:
parent
4ccd90dd42
commit
759cd0e86b
@ -34,10 +34,10 @@ Types:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <__config>
|
#include <__config>
|
||||||
|
// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
|
||||||
|
#include_next <stddef.h>
|
||||||
#include <__nullptr>
|
#include <__nullptr>
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||||
#pragma GCC system_header
|
#pragma GCC system_header
|
||||||
#endif
|
#endif
|
||||||
|
56
include/stddef.h
Normal file
56
include/stddef.h
Normal file
@ -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 <stddef.h>
|
||||||
|
|
||||||
|
#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 <stddef.h>
|
||||||
|
|
||||||
|
#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 <stddef.h> 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
|
@ -10,6 +10,7 @@
|
|||||||
// <stddef.h>
|
// <stddef.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <cassert>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
@ -22,6 +23,9 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
void *p = NULL;
|
||||||
|
assert(!p);
|
||||||
|
|
||||||
static_assert(sizeof(size_t) == sizeof(void*),
|
static_assert(sizeof(size_t) == sizeof(void*),
|
||||||
"sizeof(size_t) == sizeof(void*)");
|
"sizeof(size_t) == sizeof(void*)");
|
||||||
static_assert(std::is_unsigned<size_t>::value,
|
static_assert(std::is_unsigned<size_t>::value,
|
||||||
@ -34,4 +38,22 @@ int main()
|
|||||||
"std::is_signed<ptrdiff_t>::value");
|
"std::is_signed<ptrdiff_t>::value");
|
||||||
static_assert(std::is_integral<ptrdiff_t>::value,
|
static_assert(std::is_integral<ptrdiff_t>::value,
|
||||||
"std::is_integral<ptrdiff_t>::value");
|
"std::is_integral<ptrdiff_t>::value");
|
||||||
|
static_assert(std::is_same<decltype(nullptr), nullptr_t>::value,
|
||||||
|
"decltype(nullptr) == nullptr_t");
|
||||||
|
static_assert(sizeof(nullptr_t) == sizeof(void*),
|
||||||
|
"sizeof(nullptr_t) == sizeof(void*)");
|
||||||
|
static_assert(std::is_pod<max_align_t>::value,
|
||||||
|
"std::is_pod<max_align_t>::value");
|
||||||
|
static_assert((std::alignment_of<max_align_t>::value >=
|
||||||
|
std::alignment_of<long long>::value),
|
||||||
|
"std::alignment_of<max_align_t>::value >= "
|
||||||
|
"std::alignment_of<long long>::value");
|
||||||
|
static_assert(std::alignment_of<max_align_t>::value >=
|
||||||
|
std::alignment_of<long double>::value,
|
||||||
|
"std::alignment_of<max_align_t>::value >= "
|
||||||
|
"std::alignment_of<long double>::value");
|
||||||
|
static_assert(std::alignment_of<max_align_t>::value >=
|
||||||
|
std::alignment_of<void*>::value,
|
||||||
|
"std::alignment_of<max_align_t>::value >= "
|
||||||
|
"std::alignment_of<void*>::value");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user