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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
// RUN: %check_clang_tidy %s performance-noexcept-destructor %t -- -- -fexceptions
struct Empty
{};
struct IntWrapper {
int value;
};
template <typename T>
struct FalseT {
static constexpr bool value = false;
};
template <typename T>
struct TrueT {
static constexpr bool value = true;
};
struct ThrowOnAnything {
ThrowOnAnything() noexcept(false);
ThrowOnAnything(ThrowOnAnything&&) noexcept(false);
ThrowOnAnything& operator=(ThrowOnAnything &&) noexcept(false);
~ThrowOnAnything() noexcept(false);
};
struct B {
static constexpr bool kFalse = false;
~B() noexcept(kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false' [performance-noexcept-destructor]
};
struct D {
static constexpr bool kFalse = false;
~D() noexcept(kFalse) = default;
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false' [performance-noexcept-destructor]
};
template <typename>
struct E {
static constexpr bool kFalse = false;
~E() noexcept(kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false'
};
template <typename>
struct F {
static constexpr bool kFalse = false;
~F() noexcept(kFalse) = default;
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false' [performance-noexcept-destructor]
};
struct G {
~G() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: destructors should be marked noexcept [performance-noexcept-destructor]
// CHECK-FIXES: ~G() noexcept = default;
ThrowOnAnything field;
};
void throwing_function() noexcept(false) {}
struct H {
~H() noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false' [performance-noexcept-destructor]
};
template <typename>
struct I {
~I() noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false' [performance-noexcept-destructor]
};
template <typename T> struct TemplatedType {
static void f() {}
};
template <> struct TemplatedType<int> {
static void f() noexcept {}
};
struct J {
~J() noexcept(noexcept(TemplatedType<double>::f()));
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: noexcept specifier on the destructor evaluates to 'false' [performance-noexcept-destructor]
};
struct K : public ThrowOnAnything {
~K() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: destructors should be marked noexcept [performance-noexcept-destructor]
// CHECK-FIXES: ~K() noexcept = default;
};
struct InheritFromThrowOnAnything : public ThrowOnAnything
{};
struct L {
~L() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: destructors should be marked noexcept [performance-noexcept-destructor]
// CHECK-FIXES: ~L() noexcept = default;
InheritFromThrowOnAnything IFF;
};
struct M : public InheritFromThrowOnAnything {
~M() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: destructors should be marked noexcept [performance-noexcept-destructor]
// CHECK-FIXES: ~M() noexcept = default;
};
struct N : public IntWrapper, ThrowOnAnything {
~N() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: destructors should be marked noexcept [performance-noexcept-destructor]
// CHECK-FIXES: ~N() noexcept = default;
};
struct O : virtual IntWrapper, ThrowOnAnything {
~O() = default;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: destructors should be marked noexcept [performance-noexcept-destructor]
// CHECK-FIXES: ~O() noexcept = default;
};
class OK {};
struct OK1 {
~OK1() noexcept;
};
struct OK2 {
static constexpr bool kTrue = true;
~OK2() noexcept(true) {}
};
struct OK4 {
~OK4() noexcept(false) {}
};
struct OK3 {
~OK3() = default;
};
struct OK5 {
~OK5() noexcept(true) = default;
};
struct OK6 {
~OK6() = default;
};
template <typename>
struct OK7 {
~OK7() = default;
};
template <typename>
struct OK8 {
~OK8() noexcept = default;
};
template <typename>
struct OK9 {
~OK9() noexcept(true) = default;
};
template <typename>
struct OK10 {
~OK10() noexcept(false) = default;
};
template <typename>
struct OK11 {
~OK11() = delete;
};
void noexcept_function() noexcept {}
struct OK12 {
~OK12() noexcept(noexcept(noexcept_function()));
};
struct OK13 {
~OK13() noexcept(noexcept(noexcept_function())) = default;
};
template <typename>
struct OK14 {
~OK14() noexcept(noexcept(TemplatedType<int>::f()));
};
struct OK15 {
~OK15() = default;
int member;
};
template <typename>
struct OK16 {
~OK16() = default;
int member;
};
struct OK17 {
~OK17() = default;
OK empty_field;
};
template <typename>
struct OK18 {
~OK18() = default;
OK empty_field;
};
struct OK19 : public OK {
~OK19() = default;
};
struct OK20 : virtual OK {
~OK20() = default;
};
template <typename T>
struct OK21 : public T {
~OK21() = default;
};
template <typename T>
struct OK22 : virtual T {
~OK22() = default;
};
template <typename T>
struct OK23 {
~OK23() = default;
T member;
};
void testTemplates() {
OK21<Empty> value(OK21<Empty>{});
value = OK21<Empty>{};
OK22<Empty> value2{OK22<Empty>{}};
value2 = OK22<Empty>{};
OK23<Empty> value3{OK23<Empty>{}};
value3 =OK23<Empty>{};
}
struct OK24 : public Empty, OK1 {
~OK24() = default;
};
struct OK25 : virtual Empty, OK1 {
~OK25() = default;
};
struct OK26 : public Empty, IntWrapper {
~OK26() = default;
};
template <typename T>
struct OK27 : public T {
~OK27() = default;
};
template <typename T>
struct OK28 : virtual T {
~OK28() = default;
};
template <typename T>
struct OK29 {
~OK29() = default;
T member;
};
struct OK30 {
~OK30() noexcept(TrueT<OK30>::value) = default;
};
template <typename>
struct OK31 {
~OK31() noexcept(TrueT<int>::value) = default;
};
struct OK32 {
~OK32();
};
template <typename>
struct OK33 {
~OK33();
};
struct OK34 {
~OK34() {}
};
template <typename>
struct OK35 {
~OK35() {}
};
|