[libcxx-commits] [libcxx] b3857b2 - [libc++][NFC] Make data members of counted_iterator private (#70491)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 6 11:23:25 PST 2023


Author: Louis Dionne
Date: 2023-11-06T09:23:21-10:00
New Revision: b3857b2ecfd7064ed39aa9ae5a74c105550a05e3

URL: https://github.com/llvm/llvm-project/commit/b3857b2ecfd7064ed39aa9ae5a74c105550a05e3
DIFF: https://github.com/llvm/llvm-project/commit/b3857b2ecfd7064ed39aa9ae5a74c105550a05e3.diff

LOG: [libc++][NFC] Make data members of counted_iterator private (#70491)

There's no reason for them to be public AFAICT. I came across this while
auditing the code bases for places where we'd be using
[[no_unique_address]] incorrectly. Since one of these members is marked
as [[no_unique_address]], this is an extra reason to keep this private
to ensure the member isn't escaped anywhere.

Added: 
    

Modified: 
    libcxx/include/__iterator/counted_iterator.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__iterator/counted_iterator.h b/libcxx/include/__iterator/counted_iterator.h
index 41b7e57d28c1451..306b5f36c6e060f 100644
--- a/libcxx/include/__iterator/counted_iterator.h
+++ b/libcxx/include/__iterator/counted_iterator.h
@@ -74,9 +74,6 @@ class counted_iterator
   , public __counted_iterator_value_type<_Iter>
 {
 public:
-  _LIBCPP_NO_UNIQUE_ADDRESS _Iter __current_ = _Iter();
-  iter_
diff erence_t<_Iter> __count_ = 0;
-
   using iterator_type = _Iter;
   using 
diff erence_type = iter_
diff erence_t<_Iter>;
 
@@ -297,6 +294,12 @@ class counted_iterator
                                  "Iterators must not be past end of range.");
     return ranges::iter_swap(__x.__current_, __y.__current_);
   }
+
+private:
+  _LIBCPP_NO_UNIQUE_ADDRESS _Iter __current_ = _Iter();
+  iter_
diff erence_t<_Iter> __count_ = 0;
+  template<input_or_output_iterator _OtherIter>
+  friend class counted_iterator;
 };
 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(counted_iterator);
 


        


More information about the libcxx-commits mailing list