1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
// RUN: %check_clang_tidy %s performance-noexcept-swap %t -- -- -fexceptions
namespace std
{
template <typename T>
struct is_nothrow_move_constructible
{
static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T));
};
} // namespace std
void throwing_function() noexcept(false);
void noexcept_function() noexcept;
template <typename>
struct TemplateNoexceptWithInt {
static void f() {}
};
template <>
struct TemplateNoexceptWithInt<int> {
static void f() noexcept {}
};
class A {
void swap(A &);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(A &) noexcept ;
};
void swap(A &, A &);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(A &, A &) noexcept ;
void iter_swap(A &, A &);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void iter_swap(A &, A &) noexcept ;
struct B {
static constexpr bool kFalse = false;
void swap(B &) noexcept(kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};
void swap(B &, B &) noexcept(B::kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
template <typename>
struct C {
void swap(C&);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(C&) noexcept ;
};
template <typename T>
void swap(C<T>&, C<T>&);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(C<T>&, C<T>&) noexcept ;
void swap(C<int>&, C<int>&);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(C<int>&, C<int>&) noexcept ;
template <typename>
struct D {
static constexpr bool kFalse = false;
void swap(D &) noexcept(kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};
void swap(D<int> &, D<int> &) noexcept(D<int>::kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
struct E {
void swap(E &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};
void swap(E &, E &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
template <typename>
struct F {
void swap(F &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};
template <typename T>
void swap(F<T> &, F<T> &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
void swap(F<int> &, F<int> &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
struct G {
void swap(G &) noexcept(noexcept(TemplateNoexceptWithInt<double>::f()));
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};
void swap(G &, G &) noexcept(noexcept(TemplateNoexceptWithInt<double>::f()));
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
class OK {};
struct OK1 {
void swap(OK1 &) noexcept;
};
void swap(OK1 &, OK1 &) noexcept;
struct OK2 {
static constexpr bool kTrue = true;
void swap(OK2 &) noexcept(kTrue) {}
};
void swap(OK2 &, OK2 &) noexcept(OK2::kTrue);
struct OK3 {
void swap(OK3 &) = delete;
};
void swap(OK3 &, OK3 &) = delete;
struct OK4 {
void swap(OK4 &) noexcept(false);
};
void swap(OK4 &, OK4 &) noexcept(false);
struct OK5 {
void swap(OK5 &) noexcept(true);
};
void swap(OK5 &, OK5 &)noexcept(true);
struct OK12 {
void swap(OK12 &) noexcept(noexcept(noexcept_function()));
};
void swap(OK12 &, OK12 &) noexcept(noexcept(noexcept_function()));
struct OK13 {
void swap(OK13 &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
};
void swap(OK13 &, OK13 &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
template <typename>
class OK14 {};
template <typename>
struct OK15 {
void swap(OK15 &) noexcept;
};
template <typename T>
void swap(OK15<T> &, OK15<T> &) noexcept;
void swap(OK15<int> &, OK15<int> &) noexcept;
template <typename>
struct OK16 {
static constexpr bool kTrue = true;
void swap(OK16 &) noexcept(kTrue);
};
template <typename T>
void swap(OK16<T> &, OK16<T> &) noexcept(OK16<T>::kTrue);
template <typename T>
void swap(OK16<int> &, OK16<int> &) noexcept(OK16<int>::kTrue);
template <typename>
struct OK17 {
void swap(OK17 &) = delete;
};
template <typename T>
void swap(OK17<T> &, OK17<T> &) = delete;
void swap(OK17<int> &, OK17<int> &) = delete;
template <typename>
struct OK18 {
void swap(OK18 &) noexcept(false);
};
template <typename T>
void swap(OK18<T> &, OK18<T> &) noexcept(false);
void swap(OK18<int> &, OK18<int> &) noexcept(false);
template <typename>
struct OK19 {
void swap(OK19 &) noexcept(true);
};
template <typename T>
void swap(OK19<T> &, OK19<T> &)noexcept(true);
void swap(OK19<int> &, OK19<int> &)noexcept(true);
template <typename>
struct OK20 {
void swap(OK20 &) noexcept(noexcept(noexcept_function()));
};
template <typename T>
void swap(OK20<T> &, OK20<T> &) noexcept(noexcept(noexcept_function()));
void swap(OK20<int> &, OK20<int> &) noexcept(noexcept(noexcept_function()));
template <typename>
struct OK21 {
void swap(OK21 &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
};
template <typename T>
void swap(OK21<T> &, OK21<T> &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
void swap(OK21<int> &, OK21<int> &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
namespace PR64303 {
void swap();
void swap(int&, bool&);
void swap(int&, int&, int&);
void swap(int&);
struct Test {
void swap();
void swap(Test&, Test&);
void swap(int&);
static void swap(int&, int&);
friend void swap(Test&, Test&);
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be marked noexcept [performance-noexcept-swap]
};
} // namespace PR64303
namespace gh68101
{
template <typename T>
class Container {
public:
void swap(Container&) noexcept(std::is_nothrow_move_constructible<T>::value);
};
} // namespace gh68101
|