From 42e58b5d006e381c5dde5ea739c7225910a47f93 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 27 Feb 2023 10:04:42 -0800 Subject: [PATCH 1/4] Friendship: Use bitset's injected-class-name. --- stl/inc/bitset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/bitset b/stl/inc/bitset index 0edffa4ee4c..e9c52423198 100644 --- a/stl/inc/bitset +++ b/stl/inc/bitset @@ -29,7 +29,7 @@ public: #pragma warning(pop) class reference { // proxy for an element - friend bitset<_Bits>; + friend bitset; public: _CONSTEXPR23 reference(const reference&) = default; From 7d6f16e5edf2301df0df6f71ac987e0540093999 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 27 Feb 2023 10:21:48 -0800 Subject: [PATCH 2/4] Friendship: Consistently grant access to the parent meow_view. This avoids needing forward declarations. join_view is being updated by GH 3466. --- stl/inc/ranges | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/stl/inc/ranges b/stl/inc/ranges index f99d906a71f..02bdf4d7990 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -2327,9 +2327,6 @@ namespace ranges { /* [[no_unique_address]] */ _Vw _Range{}; /* [[no_unique_address]] */ _Movable_box<_Fn> _Fun{}; - template - class _Sentinel; - template struct _Category_base {}; @@ -2347,10 +2344,7 @@ namespace ranges { template class _Iterator : public _Category_base<_Const> { private: - template - friend class _Iterator; - template - friend class _Sentinel; + friend transform_view; using _Parent_t = _Maybe_const<_Const, transform_view>; using _Base = _Maybe_const<_Const, _Vw>; @@ -2600,8 +2594,7 @@ namespace ranges { template class _Sentinel { private: - template - friend class _Sentinel; + friend transform_view; using _Parent_t = _Maybe_const<_Const, transform_view>; using _Base = _Maybe_const<_Const, _Vw>; @@ -2773,8 +2766,7 @@ namespace ranges { template class _Sentinel { private: - template - friend class _Sentinel; + friend take_view; using _Base_t = _Maybe_const<_Const, _Vw>; using _Base_sentinel = _Maybe_wrapped<_Wrapped, sentinel_t<_Base_t>>; @@ -3067,8 +3059,7 @@ namespace ranges { template class _Sentinel { private: - template - friend class _Sentinel; + friend take_while_view; using _Base_t = _Maybe_const<_Const, _Vw>; using _Base_iterator = _Maybe_wrapped<_Wrapped, iterator_t<_Base_t>>; @@ -4472,9 +4463,7 @@ namespace ranges { template class _Outer_iter : public _Outer_iter_base>> { private: - template - friend class _Inner_iter; - friend _Outer_iter; + friend lazy_split_view; using _Mybase = _Outer_iter_base>>; using _ParentTy = _Maybe_const<_Const, lazy_split_view>; @@ -4844,11 +4833,9 @@ namespace ranges { /* [[no_unique_address]] */ _Pat _Pattern{}; _Non_propagating_cache>> _Next{}; - class _Sentinel; - class _Iterator { private: - friend _Sentinel; + friend split_view; split_view* _Parent = nullptr; iterator_t<_Vw> _Current = {}; @@ -5511,9 +5498,6 @@ namespace ranges { private: /* [[no_unique_address]] */ _Vw _Range{}; - template - class _Sentinel; - template struct _Category_base {}; @@ -5529,10 +5513,7 @@ namespace ranges { template class _Iterator : public _Category_base<_Maybe_const<_Const, _Vw>> { private: - template - friend class _Iterator; - template - friend class _Sentinel; + friend elements_view; using _Base = _Maybe_const<_Const, _Vw>; @@ -5760,8 +5741,7 @@ namespace ranges { template class _Sentinel { private: - template - friend class _Sentinel; + friend elements_view; using _Base = _Maybe_const<_Const, _Vw>; template @@ -6269,10 +6249,9 @@ namespace ranges { range_difference_t<_Vw> _Remainder = 0; _Non_propagating_cache> _Current{}; - class _Outer_iterator; class _Inner_iterator { private: - friend struct _Outer_iterator::value_type; + friend chunk_view; chunk_view* _Parent{}; constexpr explicit _Inner_iterator(chunk_view* _Parent_) noexcept : _Parent(_Parent_) {} From 38696cdad5cf48f2b7ae6ba12a0b6f5c23f5e19c Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 27 Feb 2023 10:42:21 -0800 Subject: [PATCH 3/4] Drop unnecessary forward declaration of `_Locimp`. --- stl/inc/xlocale | 2 -- 1 file changed, 2 deletions(-) diff --git a/stl/inc/xlocale b/stl/inc/xlocale index 9b99562717e..7173ef539f5 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -115,8 +115,6 @@ public: __PURE_APPDOMAIN_GLOBAL static int _Id_cnt; }; - class _Locimp; - class _CRTIMP2_PURE_IMPORT facet : public _Facet_base, public _Crt_new_delete { // base class for all locale facets, performs reference counting private: From ab5ea73848a8cdb42502647494777b5676e49a42 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 3 Mar 2023 08:18:38 -0800 Subject: [PATCH 4/4] Friendship: Use forward declarations and extended friends instead of elaborated-type-specifiers. --- stl/inc/exception | 4 +++- stl/inc/filesystem | 7 +++++-- stl/inc/xlocale | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index 1aec7bec2e6..a635cdee180 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -135,6 +135,8 @@ protected: } }; +class bad_array_new_length; + class bad_alloc : public exception { // base of all bad allocation exceptions public: __CLR_OR_THIS_CALL bad_alloc() noexcept @@ -143,7 +145,7 @@ public: __CLR_OR_THIS_CALL ~bad_alloc() noexcept override {} private: - friend class bad_array_new_length; + friend bad_array_new_length; __CLR_OR_THIS_CALL bad_alloc(const char* _Message) noexcept : exception(_Message, 1) {} // construct from message string with no memory allocation diff --git a/stl/inc/filesystem b/stl/inc/filesystem index ffa373bac8c..5f131a0f616 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2081,6 +2081,9 @@ namespace filesystem { using file_time_type = _CHRONO time_point; #endif // ^^^ !_HAS_CXX20 + struct _Dir_enum_impl; + struct _Recursive_dir_enum_impl; + _EXPORT_STD class directory_entry { public: // [fs.dir.entry.cons], constructors and destructor @@ -2473,8 +2476,8 @@ namespace filesystem { return _Error; } - friend struct _Dir_enum_impl; - friend struct _Recursive_dir_enum_impl; + friend _Dir_enum_impl; + friend _Recursive_dir_enum_impl; friend void _Copy_impl( const directory_entry& _From, const _STD filesystem::path& _To, copy_options _Options, error_code& _Ec); diff --git a/stl/inc/xlocale b/stl/inc/xlocale index 7173ef539f5..9a1c54b228b 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -115,10 +115,12 @@ public: __PURE_APPDOMAIN_GLOBAL static int _Id_cnt; }; + struct _Facet_guard; + class _CRTIMP2_PURE_IMPORT facet : public _Facet_base, public _Crt_new_delete { // base class for all locale facets, performs reference counting private: - friend struct _Facet_guard; + friend _Facet_guard; public: static size_t __CLRCALL_OR_CDECL _Getcat(const facet** = nullptr, const locale* = nullptr) {