Skip to content

Commit bffecba

Browse files
ldionnetstellar
authored andcommitted
[libc++] Simplify the implementation of <stddef.h> (#86843)
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. (cherry picked from commit 2950283)
1 parent 9899a2d commit bffecba

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

libcxx/include/stddef.h

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#if defined(__need_ptrdiff_t) || defined(__need_size_t) || defined(__need_wchar_t) || defined(__need_NULL) || \
11-
defined(__need_wint_t)
12-
13-
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
14-
# pragma GCC system_header
15-
# endif
16-
17-
# include_next <stddef.h>
18-
19-
#elif !defined(_LIBCPP_STDDEF_H)
20-
# define _LIBCPP_STDDEF_H
21-
2210
/*
2311
stddef.h synopsis
2412
@@ -36,16 +24,19 @@
3624
3725
*/
3826

39-
# include <__config>
27+
#include <__config>
28+
29+
// Note: This include is outside of header guards because we sometimes get included multiple times
30+
// with different defines and the underlying <stddef.h> will know how to deal with that.
31+
#include_next <stddef.h>
32+
33+
#ifndef _LIBCPP_STDDEF_H
34+
# define _LIBCPP_STDDEF_H
4035

4136
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4237
# pragma GCC system_header
4338
# endif
4439

45-
# if __has_include_next(<stddef.h>)
46-
# include_next <stddef.h>
47-
# endif
48-
4940
# ifdef __cplusplus
5041
typedef decltype(nullptr) nullptr_t;
5142
# endif

0 commit comments

Comments
 (0)