Skip to content

Commit f8350f1

Browse files
authored
[libc++][modules] Introduce a forward-declaration for std::byte (#107402)
We need a forward-declaration so that we can know about std::byte from some type traits without having to include std::byte's definition, which (circularly) depends back on type traits.
1 parent eb0f121 commit f8350f1

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ set(files
418418
__functional/weak_result_type.h
419419
__fwd/array.h
420420
__fwd/bit_reference.h
421+
__fwd/byte.h
421422
__fwd/complex.h
422423
__fwd/deque.h
423424
__fwd/format.h

libcxx/include/__cstddef/byte.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define _LIBCPP___CSTDDEF_BYTE_H
1111

1212
#include <__config>
13+
#include <__fwd/byte.h>
1314
#include <__type_traits/enable_if.h>
1415
#include <__type_traits/is_integral.h>
1516

libcxx/include/__fwd/byte.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===---------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_BYTE_H
10+
#define _LIBCPP___FWD_BYTE_H
11+
12+
#include <__config>
13+
14+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15+
# pragma GCC system_header
16+
#endif
17+
18+
#if _LIBCPP_STD_VER >= 17
19+
namespace std { // purposefully not versioned
20+
21+
enum class byte : unsigned char;
22+
23+
} // namespace std
24+
#endif // _LIBCPP_STD_VER >= 17
25+
26+
#endif // _LIBCPP___FWD_BYTE_H

libcxx/include/__type_traits/is_trivially_lexicographically_comparable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_LEXICOGRAPHICALLY_COMPARABLE_H
1111

1212
#include <__config>
13+
#include <__fwd/byte.h>
1314
#include <__type_traits/integral_constant.h>
1415
#include <__type_traits/is_same.h>
1516
#include <__type_traits/is_unsigned.h>
1617
#include <__type_traits/remove_cv.h>
1718
#include <__type_traits/void_t.h>
1819
#include <__utility/declval.h>
19-
#include <cstddef>
2020

2121
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222
# pragma GCC system_header

libcxx/include/module.modulemap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ module std_private_bit_reference [system] {
636636
module std_private_fwd_bit_reference [system] {
637637
header "__fwd/bit_reference.h"
638638
}
639+
module std_private_fwd_byte [system] {
640+
header "__fwd/byte.h"
641+
}
639642
module std_private_config [system] {
640643
textual header "__config"
641644
textual header "__configuration/abi.h"

libcxx/utils/generate_iwyu_mapping.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def IWYU_mapping(header: str) -> typing.Optional[typing.List[str]]:
4040
return ["atomic", "mutex", "semaphore", "thread"]
4141
elif header == "__tree":
4242
return ["map", "set"]
43+
elif header == "__fwd/byte.h":
44+
return ["cstddef"]
4345
elif header == "__fwd/pair.h":
4446
return ["utility"]
4547
elif header == "__fwd/subrange.h":

0 commit comments

Comments
 (0)