Skip to content

Commit 1dc5c43

Browse files
Fix queue/stack friendship.
queue<T, NonSpaceshipContainer> might be instantiated for a non-three_way_comparable NonSpaceshipContainer. In that case, it shouldn't attempt to grant friendship to the spaceship operator, because that would attempt to form compare_three_way_result_t<NonSpaceshipContainer>. As far as I can tell, there's no way in the Core Language for a queue to grant friendship to only one specialization of its non-member spaceship operator while respecting the constraint. (See WG21-N4861 [temp.friend]/9.) Instead, we need to template the friendship declaration, such that queue grants friendship to all of its spaceship operators. This is safe, just verbose.
1 parent f6c5510 commit 1dc5c43

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

stl/inc/queue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ public:
156156
friend bool operator> <>(const queue&, const queue&);
157157
friend bool operator<= <>(const queue&, const queue&);
158158
friend bool operator>= <>(const queue&, const queue&);
159-
#ifdef __cpp_lib_concepts
160-
friend compare_three_way_result_t<_Container> operator<=> <>(const queue&, const queue&);
161-
#endif // __cpp_lib_concepts
159+
#ifdef __cpp_lib_concepts
160+
template <class _Ty2, three_way_comparable _Container2>
161+
friend compare_three_way_result_t<_Container2> operator<=>(
162+
const queue<_Ty2, _Container2>&, const queue<_Ty2, _Container2>&);
163+
#endif // __cpp_lib_concepts
162164
// clang-format on
163165

164166
protected:

stl/inc/stack

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ public:
146146
friend bool operator> <>(const stack&, const stack&);
147147
friend bool operator<= <>(const stack&, const stack&);
148148
friend bool operator>= <>(const stack&, const stack&);
149-
#ifdef __cpp_lib_concepts
150-
friend compare_three_way_result_t<_Container> operator<=> <>(const stack&, const stack&);
151-
#endif // __cpp_lib_concepts
149+
#ifdef __cpp_lib_concepts
150+
template <class _Ty2, three_way_comparable _Container2>
151+
friend compare_three_way_result_t<_Container2> operator<=>(
152+
const stack<_Ty2, _Container2>&, const stack<_Ty2, _Container2>&);
153+
#endif // __cpp_lib_concepts
152154
// clang-format on
153155

154156
protected:

0 commit comments

Comments
 (0)