Skip to content

Commit 5acc4a3

Browse files
authored
[libc++] Remove <stddef.h> includes from the granularized <cstddef> headers (llvm#114788)
We can define some of these aliases without having to include the system <stddef.h> and there doesn't seem to be much of a reason we shouldn't do it this way.
1 parent 8c565de commit 5acc4a3

File tree

12 files changed

+14
-9
lines changed

12 files changed

+14
-9
lines changed

libcxx/include/__cstddef/nullptr_t.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
#define _LIBCPP___CSTDDEF_NULLPTR_T_H
1111

1212
#include <__config>
13-
#include <stddef.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
1716
#endif
1817

1918
_LIBCPP_BEGIN_NAMESPACE_STD
2019

21-
using ::nullptr_t;
20+
using nullptr_t = decltype(nullptr);
2221

2322
_LIBCPP_END_NAMESPACE_STD
2423

libcxx/include/__cstddef/ptrdiff_t.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
#define _LIBCPP___CSTDDEF_PTRDIFF_T_H
1111

1212
#include <__config>
13-
#include <stddef.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
1716
#endif
1817

1918
_LIBCPP_BEGIN_NAMESPACE_STD
2019

21-
using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
20+
using ptrdiff_t = decltype(static_cast<int*>(nullptr) - static_cast<int*>(nullptr));
2221

2322
_LIBCPP_END_NAMESPACE_STD
2423

libcxx/include/__cstddef/size_t.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
#define _LIBCPP___CSTDDEF_SIZE_T_H
1111

1212
#include <__config>
13-
#include <stddef.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
1716
#endif
1817

1918
_LIBCPP_BEGIN_NAMESPACE_STD
2019

21-
using ::size_t _LIBCPP_USING_IF_EXISTS;
20+
using size_t = decltype(sizeof(int));
2221

2322
_LIBCPP_END_NAMESPACE_STD
2423

libcxx/include/__exception/exception_ptr.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
1111

1212
#include <__config>
13+
#include <__cstddef/nullptr_t.h>
1314
#include <__exception/operations.h>
1415
#include <__memory/addressof.h>
1516
#include <__memory/construct_at.h>

libcxx/include/__functional/function.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <__assert>
1414
#include <__config>
15+
#include <__cstddef/nullptr_t.h>
1516
#include <__exception/exception.h>
1617
#include <__functional/binary_function.h>
1718
#include <__functional/invoke.h>

libcxx/include/__functional/hash.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define _LIBCPP___FUNCTIONAL_HASH_H
1111

1212
#include <__config>
13+
#include <__cstddef/nullptr_t.h>
1314
#include <__functional/unary_function.h>
1415
#include <__fwd/functional.h>
1516
#include <__type_traits/conjunction.h>

libcxx/include/__memory/shared_ptr.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <__compare/compare_three_way.h>
1414
#include <__compare/ordering.h>
1515
#include <__config>
16+
#include <__cstddef/nullptr_t.h>
1617
#include <__cstddef/ptrdiff_t.h>
1718
#include <__exception/exception.h>
1819
#include <__functional/binary_function.h>

libcxx/include/forward_list

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ template <class T, class Allocator, class Predicate>
200200
#include <__algorithm/lexicographical_compare_three_way.h>
201201
#include <__algorithm/min.h>
202202
#include <__config>
203+
#include <__cstddef/nullptr_t.h>
203204
#include <__iterator/distance.h>
204205
#include <__iterator/iterator_traits.h>
205206
#include <__iterator/move_iterator.h>

libcxx/include/new

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void operator delete[](void* ptr, void*) noexcept;
8787
*/
8888

8989
#include <__config>
90+
#include <__cstddef/max_align_t.h>
9091
#include <__cstddef/size_t.h>
9192
#include <__exception/exception.h>
9293
#include <__type_traits/is_function.h>

libcxx/include/string_view

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ namespace std {
208208
#include <__algorithm/min.h>
209209
#include <__assert>
210210
#include <__config>
211+
#include <__cstddef/nullptr_t.h>
211212
#include <__cstddef/ptrdiff_t.h>
212213
#include <__cstddef/size_t.h>
213214
#include <__functional/hash.h>

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
// template<class T>
3838
// strong_ordering operator<=>(shared_ptr<T> const& x, nullptr_t) noexcept; // C++20
3939

40-
#include <memory>
4140
#include <cassert>
41+
#include <cstddef>
42+
#include <memory>
4243

4344
#include "test_macros.h"
4445
#include "test_comparisons.h"

libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
// constexpr compare_three_way_result_t<typename unique_ptr<T, D>::pointer>
4040
// operator<=>(const unique_ptr<T, D>& x, nullptr_t); // C++20
4141

42-
#include <memory>
4342
#include <cassert>
44-
#include <type_traits>
43+
#include <cstddef>
44+
#include <memory>
4545

4646
#include "test_macros.h"
4747
#include "test_comparisons.h"

0 commit comments

Comments
 (0)