Skip to content

Commit 615e6dd

Browse files
authored
[🍒][libc++] Fix missing and incorrect push/pop macros (#79204) (#79497)
We recently noticed that the unwrap_iter.h file was pushing macros, but it was pushing them again instead of popping them at the end of the file. This led to libc++ basically swallowing any custom definition of these macros in user code: #define min HELLO #include <algorithm> // min is not HELLO anymore, it's not defined While investigating this issue, I noticed that our push/pop pragmas were actually entirely wrong too. Indeed, instead of pushing macros like `move`, we'd push `move(int, int)` in the pragma, which is not a valid macro name. As a result, we would not actually push macros like `move` -- instead we'd simply undefine them. This led to the following code not working: #define move HELLO #include <algorithm> // move is not HELLO anymore Fixing the pragma push/pop incantations led to a cascade of issues because we use identifiers like `move` in a large number of places, and all of these headers would now need to do the push/pop dance. This patch fixes all these issues. First, it adds a check that we don't swallow important names like min, max, move or refresh as explained above. This is done by augmenting the existing system_reserved_names.gen.py test to also check that the macros are what we expect after including each header. Second, it fixes the push/pop pragmas to work properly and adds missing pragmas to all the files I could detect a failure in via the newly added test. rdar://121365472 (cherry picked from commit 7b46225)
1 parent 2fe0bca commit 615e6dd

File tree

185 files changed

+927
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+927
-4
lines changed

libcxx/include/__algorithm/copy_move_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
# pragma GCC system_header
3232
#endif
3333

34+
_LIBCPP_PUSH_MACROS
35+
#include <__undef_macros>
36+
3437
_LIBCPP_BEGIN_NAMESPACE_STD
3538

3639
// Type traits.
@@ -132,4 +135,6 @@ __dispatch_copy_or_move(_InIter __first, _Sent __last, _OutIter __out_first) {
132135

133136
_LIBCPP_END_NAMESPACE_STD
134137

138+
_LIBCPP_POP_MACROS
139+
135140
#endif // _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H

libcxx/include/__algorithm/equal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
# pragma GCC system_header
3131
#endif
3232

33+
_LIBCPP_PUSH_MACROS
34+
#include <__undef_macros>
35+
3336
_LIBCPP_BEGIN_NAMESPACE_STD
3437

3538
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@@ -162,4 +165,6 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
162165

163166
_LIBCPP_END_NAMESPACE_STD
164167

168+
_LIBCPP_POP_MACROS
169+
165170
#endif // _LIBCPP___ALGORITHM_EQUAL_H

libcxx/include/__algorithm/equal_range.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
# pragma GCC system_header
3232
#endif
3333

34+
_LIBCPP_PUSH_MACROS
35+
#include <__undef_macros>
36+
3437
_LIBCPP_BEGIN_NAMESPACE_STD
3538

3639
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
@@ -77,4 +80,6 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
7780

7881
_LIBCPP_END_NAMESPACE_STD
7982

83+
_LIBCPP_POP_MACROS
84+
8085
#endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H

libcxx/include/__algorithm/fold.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
# pragma GCC system_header
3333
#endif
3434

35+
_LIBCPP_PUSH_MACROS
36+
#include <__undef_macros>
37+
3538
_LIBCPP_BEGIN_NAMESPACE_STD
3639

3740
#if _LIBCPP_STD_VER >= 23
@@ -122,4 +125,6 @@ inline constexpr auto fold_left = __fold_left();
122125

123126
_LIBCPP_END_NAMESPACE_STD
124127

128+
_LIBCPP_POP_MACROS
129+
125130
#endif // _LIBCPP___ALGORITHM_FOLD_H

libcxx/include/__algorithm/in_found_result.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
#if _LIBCPP_STD_VER >= 20
2225

2326
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -46,4 +49,6 @@ _LIBCPP_END_NAMESPACE_STD
4649

4750
#endif // _LIBCPP_STD_VER >= 20
4851

52+
_LIBCPP_POP_MACROS
53+
4954
#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H

libcxx/include/__algorithm/in_fun_result.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -46,4 +49,6 @@ struct in_fun_result {
4649

4750
_LIBCPP_END_NAMESPACE_STD
4851

52+
_LIBCPP_POP_MACROS
53+
4954
#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H

libcxx/include/__algorithm/in_in_out_result.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -51,4 +54,6 @@ struct in_in_out_result {
5154

5255
_LIBCPP_END_NAMESPACE_STD
5356

57+
_LIBCPP_POP_MACROS
58+
5459
#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H

libcxx/include/__algorithm/in_in_result.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -48,4 +51,6 @@ struct in_in_result {
4851

4952
_LIBCPP_END_NAMESPACE_STD
5053

54+
_LIBCPP_POP_MACROS
55+
5156
#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H

libcxx/include/__algorithm/in_out_out_result.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -49,4 +52,6 @@ struct in_out_out_result {
4952

5053
_LIBCPP_END_NAMESPACE_STD
5154

55+
_LIBCPP_POP_MACROS
56+
5257
#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H

libcxx/include/__algorithm/includes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# pragma GCC system_header
2323
#endif
2424

25+
_LIBCPP_PUSH_MACROS
26+
#include <__undef_macros>
27+
2528
_LIBCPP_BEGIN_NAMESPACE_STD
2629

2730
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
@@ -71,4 +74,6 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
7174

7275
_LIBCPP_END_NAMESPACE_STD
7376

77+
_LIBCPP_POP_MACROS
78+
7479
#endif // _LIBCPP___ALGORITHM_INCLUDES_H

0 commit comments

Comments
 (0)