Skip to content

Commit b18a46e

Browse files
authored
[libc++][NFC] Add a few clang-format annotations (#74352)
This is in preparation for clang-formatting the whole code base. These annotations are required either to avoid clang-format bugs or because the manually formatted code is significantly more readable than the clang-formatted alternative. All in all, it seems like very few annotations are required, which means that clang-format is doing a very good job in most cases.
1 parent a2e61bc commit b18a46e

19 files changed

+74
-12
lines changed

libcxx/include/__availability

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@
165165
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
166166

167167
// <filesystem>
168+
// clang-format off
168169
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
169170
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
170171
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \
171172
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000)
173+
// clang-format on
172174
# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 0
173175
# else
174176
# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1
@@ -178,6 +180,7 @@
178180
__attribute__((availability(ios,strict,introduced=13.0))) \
179181
__attribute__((availability(tvos,strict,introduced=13.0))) \
180182
__attribute__((availability(watchos,strict,introduced=6.0)))
183+
// clang-format off
181184
# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH \
182185
_Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
183186
_Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
@@ -188,12 +191,15 @@
188191
_Pragma("clang attribute pop") \
189192
_Pragma("clang attribute pop") \
190193
_Pragma("clang attribute pop")
194+
// clang-format on
191195

192196
// std::to_chars(floating-point)
197+
// clang-format off
193198
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130300) || \
194199
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300) || \
195200
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160300) || \
196201
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90300)
202+
// clang-format on
197203
# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 0
198204
# else
199205
# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 1
@@ -205,10 +211,12 @@
205211
__attribute__((availability(watchos,strict,introduced=9.3)))
206212

207213
// c++20 synchronization library
214+
// clang-format off
208215
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \
209216
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \
210217
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \
211218
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000)
219+
// clang-format on
212220
# define _LIBCPP_AVAILABILITY_HAS_SYNC 0
213221
# else
214222
# define _LIBCPP_AVAILABILITY_HAS_SYNC 1
@@ -227,10 +235,12 @@
227235
__attribute__((unavailable))
228236

229237
// std::pmr
238+
// clang-format off
230239
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \
231240
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \
232241
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \
233242
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000)
243+
// clang-format on
234244
# define _LIBCPP_AVAILABILITY_HAS_PMR 0
235245
# else
236246
# define _LIBCPP_AVAILABILITY_HAS_PMR 1
@@ -252,10 +262,12 @@
252262
# define _LIBCPP_AVAILABILITY_HAS_TZDB 0
253263
# define _LIBCPP_AVAILABILITY_TZDB __attribute__((unavailable))
254264

265+
// clang-format off
255266
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120000) || \
256267
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \
257268
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \
258269
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80000)
270+
// clang-format on
259271
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
260272
# else
261273
# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 1

libcxx/include/__format/escaped_output_table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
7575
#if _LIBCPP_STD_VER >= 23
7676

7777
namespace __escaped_output_table {
78+
// clang-format off
7879

7980
/// The entries of the characters to escape in format's debug string.
8081
///
@@ -1029,6 +1030,7 @@ inline constexpr uint32_t __unallocated_region_lower_bound = 0x000323b0;
10291030
return __code_point <= __upper_bound;
10301031
}
10311032

1033+
// clang-format on
10321034
} // namespace __escaped_output_table
10331035

10341036
#endif //_LIBCPP_STD_VER >= 23

libcxx/include/__format/extended_grapheme_cluster_table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ enum class __property : uint8_t {
124124
/// this approach uses less space for the data and is about 4% faster in the
125125
/// following benchmark.
126126
/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
127+
// clang-format off
127128
inline constexpr uint32_t __entries[1496] = {
128129
0x00000091,
129130
0x00005005,
@@ -1621,6 +1622,7 @@ inline constexpr uint32_t __entries[1496] = {
16211622
0x707787f1,
16221623
0x707b87f1,
16231624
0x707f80f1};
1625+
// clang-format on
16241626

16251627
/// Returns the extended grapheme cluster bondary property of a code point.
16261628
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __property __get_property(const char32_t __code_point) noexcept {

libcxx/include/__iterator/iter_swap.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ namespace __iter_swap {
7777
}
7878

7979
template <class _T1, class _T2>
80-
requires (!__unqualified_iter_swap<_T1, _T2> &&
81-
!__readable_swappable<_T1, _T2>) &&
82-
indirectly_movable_storable<_T1, _T2> &&
80+
requires (!__unqualified_iter_swap<_T1, _T2> && //
81+
!__readable_swappable<_T1, _T2>) && //
82+
indirectly_movable_storable<_T1, _T2> && //
8383
indirectly_movable_storable<_T2, _T1>
8484
_LIBCPP_HIDE_FROM_ABI
8585
constexpr void operator()(_T1&& __x, _T2&& __y) const
86-
noexcept(noexcept(iter_value_t<_T2>(ranges::iter_move(__y))) &&
87-
noexcept(*__y = ranges::iter_move(__x)) &&
86+
noexcept(noexcept(iter_value_t<_T2>(ranges::iter_move(__y))) && //
87+
noexcept(*__y = ranges::iter_move(__x)) && //
8888
noexcept(*_VSTD::forward<_T1>(__x) = std::declval<iter_value_t<_T2>>()))
8989
{
9090
iter_value_t<_T2> __old(ranges::iter_move(__y));

libcxx/include/__string/extern_template_lists.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# pragma GCC system_header
1616
#endif
1717

18+
// clang-format off
19+
1820
// We maintain 2 ABI lists:
1921
// - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
2022
// - _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST
@@ -126,5 +128,6 @@
126128
_Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::resize(size_type, value_type)) \
127129
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
128130

131+
// clang-format on
129132

130133
#endif // _LIBCPP___STRING_EXTERN_TEMPLATE_LISTS_H

libcxx/include/__utility/integer_sequence.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_s
5151
template<size_t _Np> struct __parity;
5252
template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
5353

54+
// clang-format off
5455
template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
5556
template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
5657
template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
@@ -68,6 +69,7 @@ template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<t
6869
template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
6970
template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
7071
template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
72+
// clang-format on
7173

7274
} // namespace detail
7375

libcxx/include/bitset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_BITSET
1111
#define _LIBCPP_BITSET
1212

13+
// clang-format off
14+
1315
/*
1416
bitset synopsis
1517
@@ -122,6 +124,8 @@ template <size_t N> struct hash<std::bitset<N>>;
122124
123125
*/
124126

127+
// clang-format on
128+
125129
#include <__algorithm/count.h>
126130
#include <__algorithm/fill.h>
127131
#include <__algorithm/find.h>

libcxx/include/chrono

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_CHRONO
1111
#define _LIBCPP_CHRONO
1212

13+
// clang-format off
14+
1315
/*
1416
chrono synopsis
1517
@@ -796,6 +798,8 @@ constexpr chrono::year operator ""y(unsigned lo
796798
} // std
797799
*/
798800

801+
// clang-format on
802+
799803
#include <__assert> // all public C++ headers provide the assertion handler
800804
#include <__chrono/calendar.h>
801805
#include <__chrono/convert_to_timespec.h>

libcxx/include/memory

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_MEMORY
1111
#define _LIBCPP_MEMORY
1212

13+
// clang-format off
14+
1315
/*
1416
memory synopsis
1517
@@ -914,6 +916,8 @@ template<size_t N, class T>
914916
915917
*/
916918

919+
// clang-format on
920+
917921
#include <__assert> // all public C++ headers provide the assertion handler
918922
#include <__config>
919923
#include <__memory/addressof.h>

libcxx/include/span

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ struct __is_std_span<span<_Tp, _Sz>> : true_type {};
182182

183183
template <class _Range, class _ElementType>
184184
concept __span_compatible_range =
185-
ranges::contiguous_range<_Range> &&
186-
ranges::sized_range<_Range> &&
187-
(ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
188-
!__is_std_span<remove_cvref_t<_Range>>::value &&
189-
!__is_std_array<remove_cvref_t<_Range>>::value &&
190-
!is_array_v<remove_cvref_t<_Range>> &&
185+
ranges::contiguous_range<_Range> && //
186+
ranges::sized_range<_Range> && //
187+
(ranges::borrowed_range<_Range> || is_const_v<_ElementType>) && //
188+
!__is_std_span<remove_cvref_t<_Range>>::value && //
189+
!__is_std_array<remove_cvref_t<_Range>>::value && //
190+
!is_array_v<remove_cvref_t<_Range>> && //
191191
is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
192192

193193
template <class _From, class _To>

libcxx/include/sstream

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_SSTREAM
1111
#define _LIBCPP_SSTREAM
1212

13+
// clang-format off
14+
1315
/*
1416
sstream synopsis [sstream.syn]
1517
@@ -266,6 +268,8 @@ typedef basic_stringstream<wchar_t> wstringstream;
266268
267269
*/
268270

271+
// clang-format on
272+
269273
#include <__assert> // all public C++ headers provide the assertion handler
270274
#include <__availability>
271275
#include <__config>

libcxx/include/string

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_STRING
1111
#define _LIBCPP_STRING
1212

13+
// clang-format off
14+
1315
/*
1416
string synopsis
1517
@@ -564,6 +566,8 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
564566
565567
*/
566568

569+
// clang-format on
570+
567571
#include <__algorithm/max.h>
568572
#include <__algorithm/min.h>
569573
#include <__algorithm/remove.h>

libcxx/include/string_view

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_STRING_VIEW
1111
#define _LIBCPP_STRING_VIEW
1212

13+
// clang-format off
14+
1315
/*
1416
1517
string_view synopsis
@@ -199,9 +201,10 @@ namespace std {
199201
200202
} // namespace std
201203
202-
203204
*/
204205

206+
// clang-format on
207+
205208
#include <__algorithm/min.h>
206209
#include <__assert> // all public C++ headers provide the assertion handler
207210
#include <__config>

libcxx/include/tuple

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_TUPLE
1111
#define _LIBCPP_TUPLE
1212

13+
// clang-format off
14+
1315
/*
1416
tuple synopsis
1517
@@ -201,6 +203,8 @@ template <class... Types>
201203
202204
*/
203205

206+
// clang-format on
207+
204208
#include <__assert> // all public C++ headers provide the assertion handler
205209
#include <__compare/common_comparison_category.h>
206210
#include <__compare/synth_three_way.h>

libcxx/include/unordered_set

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_UNORDERED_SET
1111
#define _LIBCPP_UNORDERED_SET
1212

13+
// clang-format off
14+
1315
/*
1416
1517
unordered_set synopsis
@@ -527,6 +529,8 @@ template <class Value, class Hash, class Pred, class Alloc>
527529
528530
*/
529531

532+
// clang-format on
533+
530534
#include <__algorithm/is_permutation.h>
531535
#include <__assert> // all public C++ headers provide the assertion handler
532536
#include <__availability>

libcxx/include/vector

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _LIBCPP_VECTOR
1111
#define _LIBCPP_VECTOR
1212

13+
// clang-format off
14+
1315
/*
1416
vector synopsis
1517
@@ -301,6 +303,8 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
301303
302304
*/
303305

306+
// clang-format on
307+
304308
#include <__algorithm/copy.h>
305309
#include <__algorithm/equal.h>
306310
#include <__algorithm/fill_n.h>

libcxx/src/locale.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ extern "C" const int ** __ctype_toupper_loc();
10581058
const ctype<char>::mask*
10591059
ctype<char>::classic_table() noexcept
10601060
{
1061+
// clang-format off
10611062
static constexpr const ctype<char>::mask builtin_table[table_size] = {
10621063
cntrl, cntrl,
10631064
cntrl, cntrl,
@@ -1132,6 +1133,7 @@ ctype<char>::classic_table() noexcept
11321133
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11331134
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
11341135
};
1136+
// clang-format on
11351137
return builtin_table;
11361138
}
11371139
#else

libcxx/utils/generate_escaped_output_table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
231231
#if _LIBCPP_STD_VER >= 23
232232
233233
namespace __escaped_output_table {{
234+
// clang-format off
234235
{content}
236+
// clang-format on
235237
}} // namespace __escaped_output_table
236238
237239
#endif //_LIBCPP_STD_VER >= 23

libcxx/utils/generate_extended_grapheme_cluster_table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
112112
/// this approach uses less space for the data and is about 4% faster in the
113113
/// following benchmark.
114114
/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
115+
// clang-format off
115116
inline constexpr uint32_t __entries[{size}] = {{
116117
{entries}}};
118+
// clang-format on
117119
118120
/// Returns the extended grapheme cluster bondary property of a code point.
119121
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __property __get_property(const char32_t __code_point) noexcept {{

0 commit comments

Comments
 (0)