[libcxx-commits] [libcxx] [libc++] Enable modernize-use-equals-delete (PR #93293)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 14 13:29:01 PDT 2024
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/93293
>From afa9a3b94a4e4721b5cc8306072bed3608349921 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 23 May 2024 19:14:57 +0200
Subject: [PATCH] [libc++] Enable modernize-use-equals-delete
---
libcxx/.clang-tidy | 2 +-
libcxx/include/__bit_reference | 3 +-
libcxx/include/__functional/function.h | 6 ++--
.../include/__functional/reference_wrapper.h | 2 +-
.../locale_base_api/locale_guard.h | 5 ++-
libcxx/include/__mutex/lock_guard.h | 1 -
libcxx/include/__ostream/basic_ostream.h | 6 ++--
libcxx/include/__ranges/ref_view.h | 2 +-
libcxx/include/__tree | 2 --
libcxx/include/forward_list | 6 ++--
libcxx/include/future | 5 ++-
libcxx/include/iosfwd | 6 ++--
libcxx/include/istream | 2 +-
libcxx/include/list | 6 ++--
libcxx/include/locale | 12 +++----
libcxx/include/map | 14 ++++----
libcxx/include/regex | 35 +++++++++----------
libcxx/include/tuple | 4 +--
libcxx/include/unordered_map | 8 ++---
libcxx/include/vector | 2 +-
20 files changed, 58 insertions(+), 71 deletions(-)
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/__bit_reference b/libcxx/include/__bit_reference
index 9579b9eaf70bb..391066da7d8e3 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -149,6 +149,7 @@ public:
using __container = typename _Cp::__self;
_LIBCPP_HIDE_FROM_ABI __bit_const_reference(const __bit_const_reference&) = default;
+ __bit_const_reference& operator=(const __bit_const_reference&) = delete;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
: __seg_(__x.__seg_),
@@ -167,8 +168,6 @@ private:
__storage_pointer __s, __storage_type __m) _NOEXCEPT
: __seg_(__s),
__mask_(__m) {}
-
- __bit_const_reference& operator=(const __bit_const_reference&) = delete;
};
// copy
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/__ostream/basic_ostream.h b/libcxx/include/__ostream/basic_ostream.h
index 697192bfb46b3..178359d681567 100644
--- a/libcxx/include/__ostream/basic_ostream.h
+++ b/libcxx/include/__ostream/basic_ostream.h
@@ -52,6 +52,9 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream : virtual public basic_ios<_CharT, _Tra
}
~basic_ostream() override;
+ basic_ostream(const basic_ostream& __rhs) = delete;
+ basic_ostream& operator=(const basic_ostream& __rhs) = delete;
+
protected:
inline _LIBCPP_HIDE_FROM_ABI basic_ostream(basic_ostream&& __rhs);
@@ -62,9 +65,6 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream : virtual public basic_ios<_CharT, _Tra
basic_ios<char_type, traits_type>::swap(__rhs);
}
- basic_ostream(const basic_ostream& __rhs) = delete;
- basic_ostream& operator=(const basic_ostream& __rhs) = delete;
-
public:
// 27.7.2.4 Prefix/suffix:
class _LIBCPP_TEMPLATE_VIS sentry;
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/tuple b/libcxx/include/tuple
index e7b43af7d13c0..777398ef0a03f 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -303,9 +303,9 @@ class __tuple_leaf {
# endif
}
+public:
_LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
-public:
_LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_() {
static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");
}
@@ -379,9 +379,9 @@ public:
template <size_t _Ip, class _Hp>
class __tuple_leaf<_Ip, _Hp, true> : private _Hp {
+public:
_LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
-public:
_LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
template <class _Alloc>
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;
};
More information about the libcxx-commits
mailing list