Skip to content

[libc++] Remove unnecessary friend declarations from <__tree> #152133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025

Conversation

philnik777
Copy link
Contributor

@philnik777 philnik777 commented Aug 5, 2025

Removing the unnecessary friend declarations from <__tree> also removes the need for forward declaration headers for map and set, which this patch also removes.

@philnik777 philnik777 force-pushed the tree_remove_friends branch from 3cd59de to e00b4f7 Compare August 6, 2025 10:32
@philnik777 philnik777 marked this pull request as ready for review August 7, 2025 07:18
@philnik777 philnik777 requested a review from a team as a code owner August 7, 2025 07:18
@philnik777 philnik777 merged commit 6897ca4 into llvm:main Aug 7, 2025
76 of 77 checks passed
@philnik777 philnik777 deleted the tree_remove_friends branch August 7, 2025 07:18
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 7, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Removing the unnecessary friend declarations from &lt;__tree&gt; also removes the need for forward declaration headers for map and set, which this patch also removes.


Full diff: https://github.com/llvm/llvm-project/pull/152133.diff

7 Files Affected:

  • (modified) libcxx/include/CMakeLists.txt (-2)
  • (removed) libcxx/include/__fwd/map.h (-31)
  • (removed) libcxx/include/__fwd/set.h (-30)
  • (modified) libcxx/include/__tree (+6-31)
  • (modified) libcxx/include/map (+4-2)
  • (modified) libcxx/include/module.modulemap.in (-2)
  • (modified) libcxx/include/set (+4-2)
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 51444ec668e2b..c6b87a34a43e9 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -447,14 +447,12 @@ set(files
   __fwd/get.h
   __fwd/ios.h
   __fwd/istream.h
-  __fwd/map.h
   __fwd/mdspan.h
   __fwd/memory.h
   __fwd/memory_resource.h
   __fwd/ostream.h
   __fwd/pair.h
   __fwd/queue.h
-  __fwd/set.h
   __fwd/span.h
   __fwd/sstream.h
   __fwd/stack.h
diff --git a/libcxx/include/__fwd/map.h b/libcxx/include/__fwd/map.h
deleted file mode 100644
index 940298dd3e563..0000000000000
--- a/libcxx/include/__fwd/map.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___FWD_MAP_H
-#define _LIBCPP___FWD_MAP_H
-
-#include <__config>
-#include <__fwd/functional.h>
-#include <__fwd/memory.h>
-#include <__fwd/pair.h>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
-class map;
-
-template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
-class multimap;
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___FWD_MAP_H
diff --git a/libcxx/include/__fwd/set.h b/libcxx/include/__fwd/set.h
deleted file mode 100644
index d5ef8d56b0015..0000000000000
--- a/libcxx/include/__fwd/set.h
+++ /dev/null
@@ -1,30 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___FWD_SET_H
-#define _LIBCPP___FWD_SET_H
-
-#include <__config>
-#include <__fwd/functional.h>
-#include <__fwd/memory.h>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
-class set;
-
-template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
-class multiset;
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___FWD_SET_H
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 1b1bb538029da..153db9b73006b 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -13,9 +13,7 @@
 #include <__algorithm/min.h>
 #include <__assert>
 #include <__config>
-#include <__fwd/map.h>
 #include <__fwd/pair.h>
-#include <__fwd/set.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/next.h>
@@ -686,16 +684,6 @@ private:
   friend class __tree;
   template <class, class, class>
   friend class __tree_const_iterator;
-  template <class>
-  friend class __map_iterator;
-  template <class, class, class, class>
-  friend class map;
-  template <class, class, class, class>
-  friend class multimap;
-  template <class, class, class>
-  friend class set;
-  template <class, class, class>
-  friend class multiset;
 };
 
 template <class _Tp, class _NodePtr, class _DiffType>
@@ -709,18 +697,15 @@ class __tree_const_iterator {
   __end_node_pointer __ptr_;
 
 public:
-  using iterator_category = bidirectional_iterator_tag;
-  using value_type        = __get_node_value_type_t<_Tp>;
-  using difference_type   = _DiffType;
-  using reference         = const value_type&;
-  using pointer           = __rebind_pointer_t<_NodePtr, const value_type>;
+  using iterator_category                    = bidirectional_iterator_tag;
+  using value_type                           = __get_node_value_type_t<_Tp>;
+  using difference_type                      = _DiffType;
+  using reference                            = const value_type&;
+  using pointer                              = __rebind_pointer_t<_NodePtr, const value_type>;
+  using __non_const_iterator _LIBCPP_NODEBUG = __tree_iterator<_Tp, __node_pointer, difference_type>;
 
   _LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
 
-private:
-  typedef __tree_iterator<_Tp, __node_pointer, difference_type> __non_const_iterator;
-
-public:
   _LIBCPP_HIDE_FROM_ABI __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
 
   _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__value_; }
@@ -762,16 +747,6 @@ private:
 
   template <class, class, class>
   friend class __tree;
-  template <class, class, class, class>
-  friend class map;
-  template <class, class, class, class>
-  friend class multimap;
-  template <class, class, class>
-  friend class set;
-  template <class, class, class>
-  friend class multiset;
-  template <class>
-  friend class __map_const_iterator;
 };
 
 template <class _Tp, class _Compare>
diff --git a/libcxx/include/map b/libcxx/include/map
index 0a43bd09a0b16..6378218945ca0 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -582,7 +582,6 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
 #  include <__functional/binary_function.h>
 #  include <__functional/is_transparent.h>
 #  include <__functional/operations.h>
-#  include <__fwd/map.h>
 #  include <__iterator/erase_if_container.h>
 #  include <__iterator/iterator_traits.h>
 #  include <__iterator/ranges_iterator_traits.h>
@@ -861,7 +860,10 @@ public:
   friend class __tree_const_iterator;
 };
 
-template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
+class multimap;
+
+template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
 class map {
 public:
   // types:
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index b07a153eacfae..c431c0cb407f3 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1607,7 +1607,6 @@ module std [system] {
   }
 
   module map {
-    module fwd { header "__fwd/map.h" }
     header "map"
     export *
     export std.iterator.reverse_iterator
@@ -1974,7 +1973,6 @@ module std [system] {
   }
 
   module set {
-    module fwd { header "__fwd/set.h" }
     header "set"
     export *
     export std.iterator.reverse_iterator
diff --git a/libcxx/include/set b/libcxx/include/set
index 342a5294c814f..c77345bc5dc1f 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -522,7 +522,6 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred);  // C++20
 #  include <__config>
 #  include <__functional/is_transparent.h>
 #  include <__functional/operations.h>
-#  include <__fwd/set.h>
 #  include <__iterator/erase_if_container.h>
 #  include <__iterator/iterator_traits.h>
 #  include <__iterator/ranges_iterator_traits.h>
@@ -570,7 +569,10 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Key, class _Compare, class _Allocator>
+template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
+class multiset;
+
+template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
 class set {
 public:
   // types:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants