Skip to content

[libc++] Enable modernize-use-equals-delete #93293

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
Jun 18, 2024

Conversation

philnik777
Copy link
Contributor

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

@philnik777 philnik777 requested a review from a team as a code owner May 24, 2024 10:32
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 24, 2024
@llvmbot
Copy link
Member

llvmbot commented May 24, 2024

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

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


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

17 Files Affected:

  • (modified) libcxx/.clang-tidy (+1-1)
  • (modified) libcxx/include/__functional/function.h (+3-3)
  • (modified) libcxx/include/__functional/reference_wrapper.h (+1-1)
  • (modified) libcxx/include/__locale_dir/locale_base_api/locale_guard.h (+2-3)
  • (modified) libcxx/include/__mutex/lock_guard.h (-1)
  • (modified) libcxx/include/__ranges/ref_view.h (+1-1)
  • (modified) libcxx/include/__tree (-2)
  • (modified) libcxx/include/forward_list (+2-4)
  • (modified) libcxx/include/future (+2-3)
  • (modified) libcxx/include/iosfwd (+3-3)
  • (modified) libcxx/include/istream (+1-1)
  • (modified) libcxx/include/list (+3-3)
  • (modified) libcxx/include/locale (+6-6)
  • (modified) libcxx/include/map (+6-8)
  • (modified) libcxx/include/regex (+17-18)
  • (modified) libcxx/include/unordered_map (+3-5)
  • (modified) libcxx/include/vector (+1-1)
diff --git a/libcxx/.clang-tidy b/libcxx/.clang-tidy
index ec7cab9b878ed..331c3e37dc478 100644
--- a/libcxx/.clang-tidy
+++ b/libcxx/.clang-tidy
@@ -17,6 +17,7 @@ Checks: >
   modernize-redundant-void-arg,
   modernize-use-nullptr,
   modernize-use-override,
+  modernize-use-equals-delete,
 
   readability-duplicate-include,
   readability-identifier-naming,
@@ -68,7 +69,6 @@ CheckOptions:
 # modernize-use-bool-literals,
 # modernize-use-default-member-init,
 # modernize-use-equals-default,
-# modernize-use-equals-delete,
 # portability-restrict-system-includes,
 # readability-function-cognitive-complexity,
 # readability-implicit-bool-conversion,
diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index 36057706933d4..3ca8ce1136f67 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -233,10 +233,10 @@ class _LIBCPP_TEMPLATE_VIS __base;
 
 template <class _Rp, class... _ArgTypes>
 class __base<_Rp(_ArgTypes...)> {
-  __base(const __base&);
-  __base& operator=(const __base&);
-
 public:
+  __base(const __base&) = delete;
+  __base& operator=(const __base&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI __base() {}
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual ~__base() {}
   virtual __base* __clone() const             = 0;
diff --git a/libcxx/include/__functional/reference_wrapper.h b/libcxx/include/__functional/reference_wrapper.h
index ab5d7c7cee115..3570e2673c800 100644
--- a/libcxx/include/__functional/reference_wrapper.h
+++ b/libcxx/include/__functional/reference_wrapper.h
@@ -39,7 +39,7 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
   type* __f_;
 
   static void __fun(_Tp&) _NOEXCEPT;
-  static void __fun(_Tp&&) = delete;
+  static void __fun(_Tp&&) = delete; // NOLINT(modernize-use-equals-delete) ; This is llvm.org/PR54276
 
 public:
   template <class _Up,
diff --git a/libcxx/include/__locale_dir/locale_base_api/locale_guard.h b/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
index b7e3be756e711..84095a35d3950 100644
--- a/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
+++ b/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
@@ -30,9 +30,8 @@ struct __libcpp_locale_guard {
 
   locale_t __old_loc_;
 
-private:
-  __libcpp_locale_guard(__libcpp_locale_guard const&);
-  __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
+  __libcpp_locale_guard(__libcpp_locale_guard const&) = delete;
+  __libcpp_locale_guard& operator=(__libcpp_locale_guard const&) = delete;
 };
 #elif defined(_LIBCPP_MSVCRT_LIKE)
 struct __libcpp_locale_guard {
diff --git a/libcxx/include/__mutex/lock_guard.h b/libcxx/include/__mutex/lock_guard.h
index 739d1683b317b..8340b9bbd4453 100644
--- a/libcxx/include/__mutex/lock_guard.h
+++ b/libcxx/include/__mutex/lock_guard.h
@@ -40,7 +40,6 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) loc
       : __m_(__m) {}
   _LIBCPP_HIDE_FROM_ABI ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }
 
-private:
   lock_guard(lock_guard const&)            = delete;
   lock_guard& operator=(lock_guard const&) = delete;
 };
diff --git a/libcxx/include/__ranges/ref_view.h b/libcxx/include/__ranges/ref_view.h
index 6213332a542ab..5329d778dd30d 100644
--- a/libcxx/include/__ranges/ref_view.h
+++ b/libcxx/include/__ranges/ref_view.h
@@ -43,7 +43,7 @@ class ref_view : public view_interface<ref_view<_Range>> {
   _Range* __range_;
 
   static void __fun(_Range&);
-  static void __fun(_Range&&) = delete;
+  static void __fun(_Range&&) = delete; // NOLINT(modernize-use-equals-delete) ; This is llvm.org/PR54276
 
 public:
   template <class _Tp>
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 5a0d8f42a69ce..78bafe069607d 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -651,7 +651,6 @@ public:
 
   _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); }
 
-private:
   ~__tree_node_base()                                  = delete;
   __tree_node_base(__tree_node_base const&)            = delete;
   __tree_node_base& operator=(__tree_node_base const&) = delete;
@@ -666,7 +665,6 @@ public:
 
   _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
 
-private:
   ~__tree_node()                             = delete;
   __tree_node(__tree_node const&)            = delete;
   __tree_node& operator=(__tree_node const&) = delete;
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 80dd49fe3d75a..3807a2b7dd14c 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -519,11 +519,9 @@ public:
   _LIBCPP_HIDE_FROM_ABI __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
 #endif // _LIBCPP_CXX03_LANG
 
-private:
-  __forward_list_base(const __forward_list_base&);
-  __forward_list_base& operator=(const __forward_list_base&);
+  __forward_list_base(const __forward_list_base&) = delete;
+  __forward_list_base& operator=(const __forward_list_base&) = delete;
 
-public:
   _LIBCPP_HIDE_FROM_ABI ~__forward_list_base();
 
 protected:
diff --git a/libcxx/include/future b/libcxx/include/future
index 7fa349eb8e84a..589f11a19f95f 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -1384,11 +1384,10 @@ class __packaged_task_base;
 
 template <class _Rp, class... _ArgTypes>
 class __packaged_task_base<_Rp(_ArgTypes...)> {
-  __packaged_task_base(const __packaged_task_base&);
-  __packaged_task_base& operator=(const __packaged_task_base&);
-
 public:
   _LIBCPP_HIDE_FROM_ABI __packaged_task_base() {}
+  __packaged_task_base(const __packaged_task_base&) = delete;
+  __packaged_task_base& operator=(const __packaged_task_base&) = delete;
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL
   virtual ~__packaged_task_base() {}
   virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0;
diff --git a/libcxx/include/iosfwd b/libcxx/include/iosfwd
index 2481667dd972c..051c73995e98b 100644
--- a/libcxx/include/iosfwd
+++ b/libcxx/include/iosfwd
@@ -169,10 +169,10 @@ class __save_flags {
   fmtflags __fmtflags_;
   _CharT __fill_;
 
-  __save_flags(const __save_flags&);
-  __save_flags& operator=(const __save_flags&);
-
 public:
+    __save_flags(const __save_flags&) = delete;
+    __save_flags& operator=(const __save_flags&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI explicit __save_flags(__stream_type& __stream)
       : __stream_(__stream), __fmtflags_(__stream.flags()), __fill_(__stream.fill()) {}
   _LIBCPP_HIDE_FROM_ABI ~__save_flags() {
diff --git a/libcxx/include/istream b/libcxx/include/istream
index 21269c8a8b40f..d2b577a9ad9ef 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -216,10 +216,10 @@ protected:
     basic_ios<char_type, traits_type>::swap(__rhs);
   }
 
+public:
   basic_istream(const basic_istream& __rhs)            = delete;
   basic_istream& operator=(const basic_istream& __rhs) = delete;
 
-public:
   // 27.7.1.1.3 Prefix/suffix:
   class _LIBCPP_TEMPLATE_VIS sentry;
 
diff --git a/libcxx/include/list b/libcxx/include/list
index 610a24e384600..44e87c6e982bb 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -466,10 +466,10 @@ public:
 
 template <class _Tp, class _Alloc>
 class __list_imp {
-  __list_imp(const __list_imp&);
-  __list_imp& operator=(const __list_imp&);
-
 public:
+  __list_imp(const __list_imp&) = delete;
+  __list_imp& operator=(const __list_imp&) = delete;
+
   typedef _Alloc allocator_type;
   typedef allocator_traits<allocator_type> __alloc_traits;
   typedef typename __alloc_traits::size_type size_type;
diff --git a/libcxx/include/locale b/libcxx/include/locale
index 041d7bcd27fc5..b6593e5771651 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -3148,9 +3148,6 @@ private:
   state_type __cvtstate_;
   size_t __cvtcount_;
 
-  wstring_convert(const wstring_convert& __wc);
-  wstring_convert& operator=(const wstring_convert& __wc);
-
 public:
 #ifndef _LIBCPP_CXX03_LANG
   _LIBCPP_HIDE_FROM_ABI wstring_convert() : wstring_convert(new _Codecvt) {}
@@ -3167,6 +3164,9 @@ public:
 #endif
   _LIBCPP_HIDE_FROM_ABI ~wstring_convert();
 
+  wstring_convert(const wstring_convert& __wc) = delete;
+  wstring_convert& operator=(const wstring_convert& __wc) = delete;
+
   _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); }
   _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) {
     return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));
@@ -3371,9 +3371,6 @@ private:
   bool __owns_ib_;
   bool __always_noconv_;
 
-  wbuffer_convert(const wbuffer_convert&);
-  wbuffer_convert& operator=(const wbuffer_convert&);
-
 public:
 #ifndef _LIBCPP_CXX03_LANG
   _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {}
@@ -3393,6 +3390,9 @@ public:
     return __r;
   }
 
+  wbuffer_convert(const wbuffer_convert&)            = delete;
+  wbuffer_convert& operator=(const wbuffer_convert&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; }
 
 protected:
diff --git a/libcxx/include/map b/libcxx/include/map
index 1d1c062a0267c..baa70f881d291 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -716,8 +716,6 @@ public:
 private:
   allocator_type& __na_;
 
-  __map_node_destructor& operator=(const __map_node_destructor&);
-
 public:
   bool __first_constructed;
   bool __second_constructed;
@@ -736,6 +734,8 @@ public:
   }
 #endif // _LIBCPP_CXX03_LANG
 
+  __map_node_destructor& operator=(const __map_node_destructor&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
     if (__second_constructed)
       __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().second));
@@ -809,7 +809,6 @@ public:
     return *this;
   }
 
-private:
   __value_type()                    = delete;
   ~__value_type()                   = delete;
   __value_type(const __value_type&) = delete;
@@ -831,11 +830,10 @@ public:
   _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
   _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
 
-private:
-  __value_type();
-  __value_type(__value_type const&);
-  __value_type& operator=(__value_type const&);
-  ~__value_type();
+  __value_type()                               = delete;
+  __value_type(__value_type const&)            = delete;
+  __value_type& operator=(__value_type const&) = delete;
+  ~__value_type()                              = delete;
 };
 
 #endif // _LIBCPP_CXX03_LANG
diff --git a/libcxx/include/regex b/libcxx/include/regex
index ce9f34260254a..515dccca2de00 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -1346,13 +1346,12 @@ struct __state {
 
 template <class _CharT>
 class __node {
-  __node(const __node&);
-  __node& operator=(const __node&);
-
 public:
   typedef std::__state<_CharT> __state;
 
   _LIBCPP_HIDE_FROM_ABI __node() {}
+  __node(const __node&)            = delete;
+  __node& operator=(const __node&) = delete;
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL
   virtual ~__node() {}
 
@@ -1953,14 +1952,14 @@ class __match_char : public __owns_one_state<_CharT> {
 
   _CharT __c_;
 
-  __match_char(const __match_char&);
-  __match_char& operator=(const __match_char&);
-
 public:
   typedef std::__state<_CharT> __state;
 
   _LIBCPP_HIDE_FROM_ABI __match_char(_CharT __c, __node<_CharT>* __s) : base(__s), __c_(__c) {}
 
+  __match_char(const __match_char&) = delete;
+  __match_char& operator=(const __match_char&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
 };
 
@@ -1985,15 +1984,15 @@ class __match_char_icase : public __owns_one_state<_CharT> {
   _Traits __traits_;
   _CharT __c_;
 
-  __match_char_icase(const __match_char_icase&);
-  __match_char_icase& operator=(const __match_char_icase&);
-
 public:
   typedef std::__state<_CharT> __state;
 
   _LIBCPP_HIDE_FROM_ABI __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
       : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
 
+  __match_char_icase(const __match_char_icase&) = delete;
+  __match_char_icase& operator=(const __match_char_icase&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
 };
 
@@ -2018,15 +2017,15 @@ class __match_char_collate : public __owns_one_state<_CharT> {
   _Traits __traits_;
   _CharT __c_;
 
-  __match_char_collate(const __match_char_collate&);
-  __match_char_collate& operator=(const __match_char_collate&);
-
 public:
   typedef std::__state<_CharT> __state;
 
   _LIBCPP_HIDE_FROM_ABI __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
       : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
 
+  __match_char_collate(const __match_char_collate&)            = delete;
+  __match_char_collate& operator=(const __match_char_collate&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
 };
 
@@ -2062,9 +2061,6 @@ class __bracket_expression : public __owns_one_state<_CharT> {
   bool __collate_;
   bool __might_have_digraph_;
 
-  __bracket_expression(const __bracket_expression&);
-  __bracket_expression& operator=(const __bracket_expression&);
-
 public:
   typedef std::__state<_CharT> __state;
 
@@ -2079,6 +2075,9 @@ public:
         __collate_(__collate),
         __might_have_digraph_(__traits_.getloc().name() != "C") {}
 
+  __bracket_expression(const __bracket_expression&)            = delete;
+  __bracket_expression& operator=(const __bracket_expression&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
 
   _LIBCPP_HIDE_FROM_ABI bool __negated() const { return __negate_; }
@@ -2700,9 +2699,6 @@ class __lookahead : public __owns_one_state<_CharT> {
   unsigned __mexp_;
   bool __invert_;
 
-  __lookahead(const __lookahead&);
-  __lookahead& operator=(const __lookahead&);
-
 public:
   typedef std::__state<_CharT> __state;
 
@@ -2710,6 +2706,9 @@ public:
   __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
       : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
 
+  __lookahead(const __lookahead&) = delete;
+  __lookahead& operator=(const __lookahead&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
 };
 
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index c838cd96b1123..ecf3bad17780a 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -793,12 +793,12 @@ public:
 private:
   allocator_type& __na_;
 
-  __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
-
 public:
   bool __first_constructed;
   bool __second_constructed;
 
+  __hash_map_node_destructor& operator=(const __hash_map_node_destructor&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
       : __na_(__na),
         __first_constructed(false),
@@ -883,7 +883,6 @@ public:
     return *this;
   }
 
-private:
   __hash_value_type(const __hash_value_type& __v) = delete;
   __hash_value_type(__hash_value_type&& __v)      = delete;
   template <class... _Args>
@@ -907,8 +906,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
   _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
 
-private:
-  ~__hash_value_type();
+  ~__hash_value_type() = delete;
 };
 
 #endif
diff --git a/libcxx/include/vector b/libcxx/include/vector
index b190557fb7b7e..45cf2da98395f 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -897,6 +897,7 @@ private:
       __v_.__annotate_increase(__n);
 #endif
     }
+
     _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
       __v_.__end_ = __pos_;
 #ifndef _LIBCPP_HAS_NO_ASAN
@@ -910,7 +911,6 @@ private:
     pointer __pos_;
     const_pointer const __new_end_;
 
-  private:
     _ConstructTransaction(_ConstructTransaction const&)            = delete;
     _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
   };

Copy link

github-actions bot commented May 24, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@philnik777 philnik777 force-pushed the modernize_use_equals_delete branch 3 times, most recently from 97ffbfe to daefaa7 Compare June 14, 2024 20:57
Copy link
Member

@EricWF EricWF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the CI comes back.

@philnik777 philnik777 force-pushed the modernize_use_equals_delete branch from daefaa7 to bb2824a Compare June 17, 2024 11:24
@philnik777 philnik777 merged commit bbe4a80 into llvm:main Jun 18, 2024
56 of 57 checks passed
@philnik777 philnik777 deleted the modernize_use_equals_delete branch June 18, 2024 08:52
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.

3 participants