[libcxx-commits] [libcxx] feb80aa - [libc++] `= delete` member functions with // = delete;

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 8 10:30:40 PST 2021


Author: Nikolas Klauser
Date: 2021-12-08T19:29:44+01:00
New Revision: feb80aa96ba68e9599de61ce87e68650c1dae699

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

LOG: [libc++] `= delete` member functions with // = delete;

Use `= delete` for member functions that are marked with `// = delete;`

Reviewed By: ldionne, Quuxplusone, #libc

Spies: jloser, libcxx-commits

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

Added: 
    

Modified: 
    libcxx/include/__functional/function.h
    libcxx/include/__locale
    libcxx/include/__mutex_base
    libcxx/include/__random/random_device.h
    libcxx/include/__random/seed_seq.h
    libcxx/include/ios
    libcxx/include/istream
    libcxx/include/mutex
    libcxx/include/ostream
    libcxx/include/system_error

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index 0a17b0bf97f50..8336d85adf2eb 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -1717,13 +1717,11 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp()>
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2>
-      bool operator==(const function<_R2()>&) const;// = delete;
+      bool operator==(const function<_R2()>&) const = delete;
     template<class _R2>
-      bool operator!=(const function<_R2()>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2()>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()() const;
 
@@ -1997,13 +1995,11 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)>
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2, class _B0>
-      bool operator==(const function<_R2(_B0)>&) const;// = delete;
+      bool operator==(const function<_R2(_B0)>&) const = delete;
     template<class _R2, class _B0>
-      bool operator!=(const function<_R2(_B0)>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2(_B0)>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()(_A0) const;
 
@@ -2277,13 +2273,11 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)>
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2, class _B0, class _B1>
-      bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
+      bool operator==(const function<_R2(_B0, _B1)>&) const = delete;
     template<class _R2, class _B0, class _B1>
-      bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2(_B0, _B1)>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()(_A0, _A1) const;
 
@@ -2556,13 +2550,11 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)>
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2, class _B0, class _B1, class _B2>
-      bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
+      bool operator==(const function<_R2(_B0, _B1, _B2)>&) const = delete;
     template<class _R2, class _B0, class _B1, class _B2>
-      bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()(_A0, _A1, _A2) const;
 

diff  --git a/libcxx/include/__locale b/libcxx/include/__locale
index 4296adbbd8e92..2582a90bb5781 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -208,10 +208,11 @@ class _LIBCPP_TYPE_VIS locale::id
     static int32_t __next_id;
 public:
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
+    void operator=(const id&) = delete;
+    id(const id&) = delete;
+
 private:
     void __init();
-    void operator=(const id&); // = delete;
-    id(const id&); // = delete;
 public:  // only needed for tests
     long __get();
 

diff  --git a/libcxx/include/__mutex_base b/libcxx/include/__mutex_base
index da2967164a681..21e2075603b55 100644
--- a/libcxx/include/__mutex_base
+++ b/libcxx/include/__mutex_base
@@ -140,11 +140,9 @@ public:
             __m_->unlock();
     }
 
-private:
-    unique_lock(unique_lock const&); // = delete;
-    unique_lock& operator=(unique_lock const&); // = delete;
+    unique_lock(unique_lock const&) = delete;
+    unique_lock& operator=(unique_lock const&) = delete;
 
-public:
     _LIBCPP_INLINE_VISIBILITY
     unique_lock(unique_lock&& __u) _NOEXCEPT
         : __m_(__u.__m_), __owns_(__u.__owns_)

diff  --git a/libcxx/include/__random/random_device.h b/libcxx/include/__random/random_device.h
index f62f7a3d269bb..6a6b0cc306674 100644
--- a/libcxx/include/__random/random_device.h
+++ b/libcxx/include/__random/random_device.h
@@ -56,10 +56,8 @@ class _LIBCPP_TYPE_VIS random_device
     // property functions
     double entropy() const _NOEXCEPT;
 
-private:
-    // no copy functions
-    random_device(const random_device&); // = delete;
-    random_device& operator=(const random_device&); // = delete;
+    random_device(const random_device&) = delete;
+    void operator=(const random_device&) = delete;
 };
 
 #endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE

diff  --git a/libcxx/include/__random/seed_seq.h b/libcxx/include/__random/seed_seq.h
index 97bc88d0d4d15..bf27af6627a54 100644
--- a/libcxx/include/__random/seed_seq.h
+++ b/libcxx/include/__random/seed_seq.h
@@ -63,10 +63,8 @@ class _LIBCPP_TEMPLATE_VIS seed_seq
         void param(_OutputIterator __dest) const
             {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
 
-private:
-    // no copy functions
-    seed_seq(const seed_seq&); // = delete;
-    void operator=(const seed_seq&); // = delete;
+    seed_seq(const seed_seq&) = delete;
+    void operator=(const seed_seq&) = delete;
 
     _LIBCPP_INLINE_VISIBILITY
     static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}

diff  --git a/libcxx/include/ios b/libcxx/include/ios
index b7d32946bff03..237d146dfb85c 100644
--- a/libcxx/include/ios
+++ b/libcxx/include/ios
@@ -308,11 +308,9 @@ public:
     typedef void (*event_callback)(event, ios_base&, int __index);
     void register_callback(event_callback __fn, int __index);
 
-private:
-    ios_base(const ios_base&); // = delete;
-    ios_base& operator=(const ios_base&); // = delete;
+    ios_base(const ios_base&) = delete;
+    ios_base& operator=(const ios_base&) = delete;
 
-public:
     static bool sync_with_stdio(bool __sync = true);
 
     _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;

diff  --git a/libcxx/include/istream b/libcxx/include/istream
index 2f39e35f46464..de49d49e45645 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -291,15 +291,15 @@ class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
 {
     bool __ok_;
 
-    sentry(const sentry&); // = delete;
-    sentry& operator=(const sentry&); // = delete;
-
 public:
     explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
 //    ~sentry() = default;
 
     _LIBCPP_INLINE_VISIBILITY
     explicit operator bool() const {return __ok_;}
+
+    sentry(const sentry&) = delete;
+    sentry& operator=(const sentry&) = delete;
 };
 
 template <class _CharT, class _Traits>

diff  --git a/libcxx/include/mutex b/libcxx/include/mutex
index 822abe1a3f170..b2a4d7993e0db 100644
--- a/libcxx/include/mutex
+++ b/libcxx/include/mutex
@@ -215,14 +215,12 @@ class _LIBCPP_TYPE_VIS recursive_mutex
     __libcpp_recursive_mutex_t __m_;
 
 public:
-     recursive_mutex();
-     ~recursive_mutex();
+    recursive_mutex();
+    ~recursive_mutex();
 
-private:
-    recursive_mutex(const recursive_mutex&); // = delete;
-    recursive_mutex& operator=(const recursive_mutex&); // = delete;
+    recursive_mutex(const recursive_mutex&) = delete;
+    recursive_mutex& operator=(const recursive_mutex&) = delete;
 
-public:
     void lock();
     bool try_lock() _NOEXCEPT;
     void unlock()  _NOEXCEPT;
@@ -242,9 +240,8 @@ public:
      timed_mutex();
      ~timed_mutex();
 
-private:
-    timed_mutex(const timed_mutex&); // = delete;
-    timed_mutex& operator=(const timed_mutex&); // = delete;
+    timed_mutex(const timed_mutex&) = delete;
+    timed_mutex& operator=(const timed_mutex&) = delete;
 
 public:
     void lock();
@@ -283,14 +280,12 @@ class _LIBCPP_TYPE_VIS recursive_timed_mutex
     size_t             __count_;
     __thread_id        __id_;
 public:
-     recursive_timed_mutex();
-     ~recursive_timed_mutex();
+    recursive_timed_mutex();
+    ~recursive_timed_mutex();
 
-private:
-    recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
-    recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
+    recursive_timed_mutex(const recursive_timed_mutex&) = delete;
+    recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
 
-public:
     void lock();
     bool try_lock() _NOEXCEPT;
     template <class _Rep, class _Period>
@@ -576,6 +571,8 @@ struct _LIBCPP_TEMPLATE_VIS once_flag
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR
         once_flag() _NOEXCEPT : __state_(0) {}
+    once_flag(const once_flag&) = delete;
+    once_flag& operator=(const once_flag&) = delete;
 
 #if defined(_LIBCPP_ABI_MICROSOFT)
    typedef uintptr_t _State_type;
@@ -583,11 +580,7 @@ struct _LIBCPP_TEMPLATE_VIS once_flag
    typedef unsigned long _State_type;
 #endif
 
-
 private:
-    once_flag(const once_flag&); // = delete;
-    once_flag& operator=(const once_flag&); // = delete;
-
     _State_type __state_;
 
 #ifndef _LIBCPP_CXX03_LANG

diff  --git a/libcxx/include/ostream b/libcxx/include/ostream
index 98f36ea7acc10..d948d591c8f05 100644
--- a/libcxx/include/ostream
+++ b/libcxx/include/ostream
@@ -249,12 +249,11 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
     bool __ok_;
     basic_ostream<_CharT, _Traits>& __os_;
 
-    sentry(const sentry&); // = delete;
-    sentry& operator=(const sentry&); // = delete;
-
 public:
     explicit sentry(basic_ostream<_CharT, _Traits>& __os);
     ~sentry();
+    sentry(const sentry&) = delete;
+    sentry& operator=(const sentry&) = delete;
 
     _LIBCPP_INLINE_VISIBILITY
     explicit operator bool() const {return __ok_;}

diff  --git a/libcxx/include/system_error b/libcxx/include/system_error
index 0bd2d2363882c..059fa0e2d511b 100644
--- a/libcxx/include/system_error
+++ b/libcxx/include/system_error
@@ -208,11 +208,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
 #endif
-private:
-    error_category(const error_category&);// = delete;
-    error_category& operator=(const error_category&);// = delete;
+    error_category(const error_category&) = delete;
+    error_category& operator=(const error_category&) = delete;
 
-public:
     virtual const char* name() const _NOEXCEPT = 0;
     virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
     virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;


        


More information about the libcxx-commits mailing list