Skip to content

Commit

Permalink
[libc++] Simplify the implementation of <stddef.h> (#86843)
Browse files Browse the repository at this point in the history
Libc++'s own <stddef.h> is complicated by the need to handle various
platform-specific macros and to support duplicate inclusion. In reality,
we only need to add a declaration of nullptr_t to it, so we can simply
include the underlying <stddef.h> outside of our guards to let it handle
re-inclusion itself.
  • Loading branch information
ldionne authored Apr 2, 2024
1 parent beeb15b commit 2950283
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions libcxx/include/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
//
//===----------------------------------------------------------------------===//

#if defined(__need_ptrdiff_t) || defined(__need_size_t) || defined(__need_wchar_t) || defined(__need_NULL) || \
defined(__need_wint_t)

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

# include_next <stddef.h>

#elif !defined(_LIBCPP_STDDEF_H)
# define _LIBCPP_STDDEF_H

/*
stddef.h synopsis
Expand All @@ -36,16 +24,19 @@
*/

# include <__config>
#include <__config>

// Note: This include is outside of header guards because we sometimes get included multiple times
// with different defines and the underlying <stddef.h> will know how to deal with that.
#include_next <stddef.h>

#ifndef _LIBCPP_STDDEF_H
# define _LIBCPP_STDDEF_H

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

# if __has_include_next(<stddef.h>)
# include_next <stddef.h>
# endif

# ifdef __cplusplus
typedef decltype(nullptr) nullptr_t;
# endif
Expand Down

0 comments on commit 2950283

Please sign in to comment.