[libcxx-commits] [libcxx] 70d94c3 - [libc++] __bit_iterator mustn't rely on deprecated SMF generation.

Arthur O'Dwyer via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 26 13:23:26 PDT 2021


Author: Arthur O'Dwyer
Date: 2021-04-26T16:22:42-04:00
New Revision: 70d94c3f2cae71ade2ceacdceb3d2e9899d2289a

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

LOG: [libc++] __bit_iterator mustn't rely on deprecated SMF generation.

This allows us to turn -Wdeprecated-copy back on. We turned it off
in 3b71de41cc7c7 because Clang's implementation became more stringent
and started diagnosing the old code here.

Differential Revision: https://reviews.llvm.org/D101183

Added: 
    

Modified: 
    libcxx/include/__bit_reference
    libcxx/utils/libcxx/test/params.py

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index aa22d5d178370..a02492c077dd6 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -1114,28 +1114,26 @@ public:
 #endif
     {}
 
-    // avoid re-declaring a copy constructor for the non-const version.
-    using __type_for_copy_to_const =
-      _If<_IsConst, __bit_iterator<_Cp, false>, struct __private_nat>;
-
+    // When _IsConst=false, this is the copy constructor.
+    // It is non-trivial. Making it trivial would break ABI.
+    // When _IsConst=true, this is a converting constructor;
+    // the copy and move constructors are implicitly generated
+    // and trivial.
     _LIBCPP_INLINE_VISIBILITY
-    __bit_iterator(const __type_for_copy_to_const& __it) _NOEXCEPT
+    __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
         : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
 
-    // The non-const __bit_iterator has historically had a non-trivial
-    // copy constructor (as a quirk of its construction). We need to maintain
-    // this for ABI purposes.
-    using __type_for_abi_non_trivial_copy_ctor =
-      _If<!_IsConst, __bit_iterator, struct __private_nat>;
-
-    _LIBCPP_INLINE_VISIBILITY
-    __bit_iterator(__type_for_abi_non_trivial_copy_ctor const& __it) _NOEXCEPT
-      : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
-
-    // Always declare the copy assignment operator since the implicit declaration
-    // is deprecated.
+    // When _IsConst=false, we have a user-provided copy constructor,
+    // so we must also provide a copy assignment operator because
+    // the implicit generation of a defaulted one is deprecated.
+    // When _IsConst=true, the assignment operators are
+    // implicitly generated and trivial.
     _LIBCPP_INLINE_VISIBILITY
-    __bit_iterator& operator=(__bit_iterator const&) = default;
+    __bit_iterator& operator=(const _If<_IsConst, struct __private_nat, __bit_iterator>& __it) {
+        __seg_ = __it.__seg_;
+        __ctz_ = __it.__ctz_;
+        return *this;
+    }
 
     _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
         {return reference(__seg_, __storage_type(1) << __ctz_);}

diff  --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 7616f88028cb2..ddf277dea2469 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -13,7 +13,6 @@
   '-Werror',
   '-Wall',
   '-Wextra',
-  '-Wno-deprecated-copy',
   '-Wshadow',
   '-Wundef',
   '-Wno-unused-command-line-argument',


        


More information about the libcxx-commits mailing list