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 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
|
// RUN: %check_clang_tidy %s performance-move-const-arg %t
namespace std {
template <typename>
struct remove_reference;
template <typename _Tp>
struct remove_reference {
typedef _Tp type;
};
template <typename _Tp>
struct remove_reference<_Tp &> {
typedef _Tp type;
};
template <typename _Tp>
struct remove_reference<_Tp &&> {
typedef _Tp type;
};
template <typename _Tp>
constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
}
template <typename _Tp>
constexpr _Tp &&
forward(typename remove_reference<_Tp>::type &__t) noexcept {
return static_cast<_Tp &&>(__t);
}
} // namespace std
class A {
public:
A() {}
A(const A &rhs) {}
A(A &&rhs) {}
};
using AlsoA = A;
struct TriviallyCopyable {
int i;
};
using TrivialAlias = TriviallyCopyable;
void f(TriviallyCopyable) {}
void g() {
TriviallyCopyable obj;
f(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: f(obj);
TrivialAlias obj2;
f(std::move(obj2));
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj2' of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: f(obj2);
}
int f1() {
return std::move(42);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'int' has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: return 42;
}
int f2(int x2) {
return std::move(x2);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x2' of the trivially-copyable type 'int'
// CHECK-FIXES: return x2;
}
int *f3(int *x3) {
return std::move(x3);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x3' of the trivially-copyable type 'int *'
// CHECK-FIXES: return x3;
}
A f4(A x4) { return std::move(x4); }
AlsoA f4_a(AlsoA x4) { return std::move(x4); }
A f5(const A x5) {
return std::move(x5);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
// CHECK-FIXES: return x5;
}
AlsoA f5_a(const AlsoA x5) {
return std::move(x5);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
// CHECK-FIXES: return x5;
}
template <typename T>
T f6(const T x6) {
return std::move(x6);
}
void f7() { int a = f6(10); }
#define M1(x) x
void f8() {
const A a;
M1(A b = std::move(a);)
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable 'a' has no effect; remove std::move() or make the variable non-const
// CHECK-FIXES: M1(A b = a;)
}
#define M2(x) std::move(x)
int f9() { return M2(1); }
template <typename T>
T f10(const int x10) {
return std::move(x10);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: return x10;
}
void f11() {
f10<int>(1);
f10<double>(1);
}
class NoMoveSemantics {
public:
NoMoveSemantics();
NoMoveSemantics(const NoMoveSemantics &);
NoMoveSemantics &operator=(const NoMoveSemantics &);
};
using NoMoveSemanticsAlias = NoMoveSemantics;
void callByConstRef(const NoMoveSemantics &);
void callByConstRef(int i, const NoMoveSemantics &);
void moveToConstReferencePositives() {
NoMoveSemantics obj;
// Basic case.
callByConstRef(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as
// CHECK-FIXES: callByConstRef(obj);
// Also works for second argument.
callByConstRef(1, std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as
// CHECK-FIXES: callByConstRef(1, obj);
// Works if std::move() applied to a temporary.
callByConstRef(std::move(NoMoveSemantics()));
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as
// CHECK-FIXES: callByConstRef(NoMoveSemantics());
// Works if calling a copy constructor.
NoMoveSemantics other(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: passing result of std::move() as
// CHECK-FIXES: NoMoveSemantics other(obj);
// Works if calling assignment operator.
other = std::move(obj);
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as
// CHECK-FIXES: other = obj;
}
void moveToConstReferencePositivesAlias() {
NoMoveSemanticsAlias obj;
// Basic case.
callByConstRef(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-FIXES: callByConstRef(obj);
// Also works for second argument.
callByConstRef(1, std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-FIXES: callByConstRef(1, obj);
// Works if std::move() applied to a temporary.
callByConstRef(std::move(NoMoveSemanticsAlias()));
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-FIXES: callByConstRef(NoMoveSemanticsAlias());
// Works if calling a copy constructor.
NoMoveSemanticsAlias other(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-FIXES: NoMoveSemanticsAlias other(obj);
// Works if calling assignment operator.
other = std::move(obj);
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-FIXES: other = obj;
}
class MoveSemantics {
public:
MoveSemantics();
MoveSemantics(MoveSemantics &&);
MoveSemantics &operator=(MoveSemantics &&);
};
using MoveSemanticsAlias = MoveSemantics;
void callByValue(MoveSemantics);
void callByRValueRef(MoveSemantics &&);
template <class T>
void templateFunction(T obj) {
T other = std::move(obj);
}
#define M3(T, obj) \
do { \
T other = std::move(obj); \
} while (true)
#define CALL(func) (func)()
void moveToConstReferenceNegatives() {
// No warning when actual move takes place.
MoveSemantics move_semantics;
callByValue(std::move(move_semantics));
callByRValueRef(std::move(move_semantics));
MoveSemantics other(std::move(move_semantics));
other = std::move(move_semantics);
// No warning if std::move() not used.
NoMoveSemantics no_move_semantics;
callByConstRef(no_move_semantics);
// No warning if instantiating a template.
templateFunction(no_move_semantics);
// No warning inside of macro expansions.
M3(NoMoveSemantics, no_move_semantics);
// No warning inside of macro expansion, even if the macro expansion is inside
// a lambda that is, in turn, an argument to a macro.
CALL([no_move_semantics] { M3(NoMoveSemantics, no_move_semantics); });
auto lambda = [] {};
auto lambda2 = std::move(lambda);
}
void moveToConstReferenceNegativesAlias() {
// No warning when actual move takes place.
MoveSemanticsAlias move_semantics;
callByValue(std::move(move_semantics));
callByRValueRef(std::move(move_semantics));
MoveSemanticsAlias other(std::move(move_semantics));
other = std::move(move_semantics);
// No warning if std::move() not used.
NoMoveSemanticsAlias no_move_semantics;
callByConstRef(no_move_semantics);
// No warning if instantiating a template.
templateFunction(no_move_semantics);
// No warning inside of macro expansions.
M3(NoMoveSemanticsAlias, no_move_semantics);
// No warning inside of macro expansion, even if the macro expansion is inside
// a lambda that is, in turn, an argument to a macro.
CALL([no_move_semantics] { M3(NoMoveSemanticsAlias, no_move_semantics); });
auto lambda = [] {};
auto lambda2 = std::move(lambda);
}
class MoveOnly {
public:
MoveOnly(const MoveOnly &other) = delete;
MoveOnly &operator=(const MoveOnly &other) = delete;
MoveOnly(MoveOnly &&other) = default;
MoveOnly &operator=(MoveOnly &&other) = default;
};
template <class T>
void Q(T);
void moveOnlyNegatives(MoveOnly val) {
Q(std::move(val));
}
using MoveOnlyAlias = MoveOnly;
void fmovable(MoveSemantics);
void lambda1() {
auto f = [](MoveSemantics m) {
fmovable(std::move(m));
};
f(MoveSemantics());
}
template<class T> struct function {};
template<typename Result, typename... Args>
class function<Result(Args...)> {
public:
function() = default;
void operator()(Args... args) const {
fmovable(std::forward<Args>(args)...);
}
};
void functionInvocation() {
function<void(MoveSemantics)> callback;
MoveSemantics m;
callback(std::move(m));
}
void functionInvocationAlias() {
function<void(MoveSemanticsAlias)> callback;
MoveSemanticsAlias m;
callback(std::move(m));
}
void lambda2() {
function<void(MoveSemantics)> callback;
auto f = [callback = std::move(callback)](MoveSemantics m) mutable {
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: std::move of the variable 'callback' of the trivially-copyable type 'function<void (MoveSemantics)>' has no effect; remove std::move()
// CHECK-FIXES: auto f = [callback = callback](MoveSemantics m) mutable {
callback(std::move(m));
};
f(MoveSemantics());
}
void lambda2Alias() {
function<void(MoveSemanticsAlias)> callback;
auto f = [callback = std::move(callback)](MoveSemanticsAlias m) mutable {
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: std::move of the variable 'callback' of the trivially-copyable type 'function<void (MoveSemanticsAlias)>' (aka 'function<void (MoveSemantics)>') has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: auto f = [callback = callback](MoveSemanticsAlias m) mutable {
callback(std::move(m));
};
f(MoveSemanticsAlias());
}
void showInt(int &&v);
void showInt(int v1, int &&v2);
void showPointer(const char *&&s);
void showPointer2(const char *const &&s);
void showTriviallyCopyable(TriviallyCopyable &&obj);
void showTriviallyCopyablePointer(const TriviallyCopyable *&&obj);
void testFunctions() {
int a = 10;
showInt(std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-10]]:20: note: consider changing the 1st parameter of 'showInt' from 'int &&' to 'const int &'
showInt(int());
showInt(a, std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-13]]:28: note: consider changing the 2nd parameter of 'showInt' from 'int &&' to 'const int &'
const char* s = "";
showPointer(std::move(s));
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: std::move of the variable 's' of the trivially-copyable type 'const char *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-16]]:32: note: consider changing the 1st parameter of 'showPointer' from 'const char *&&' to 'const char *'
showPointer2(std::move(s));
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: std::move of the variable 's' of the trivially-copyable type 'const char *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-18]]:39: note: consider changing the 1st parameter of 'showPointer2' from 'const char *const &&' to 'const char *const'
TriviallyCopyable *obj = new TriviallyCopyable();
showTriviallyCopyable(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: std::move of the expression of the trivially-copyable type 'TriviallyCopyable' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-21]]:48: note: consider changing the 1st parameter of 'showTriviallyCopyable' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
showTriviallyCopyablePointer(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-23]]:62: note: consider changing the 1st parameter of 'showTriviallyCopyablePointer' from 'const TriviallyCopyable *&&' to 'const TriviallyCopyable *'
TrivialAlias* obj2 = new TrivialAlias();
showTriviallyCopyable(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: std::move of the expression of the trivially-copyable type 'TriviallyCopyable' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-28]]:48: note: consider changing the 1st parameter of 'showTriviallyCopyable' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
showTriviallyCopyablePointer(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-30]]:62: note: consider changing the 1st parameter of 'showTriviallyCopyablePointer' from 'const TriviallyCopyable *&&' to 'const TriviallyCopyable *'
}
template <class T>
void forwardToShowInt(T && t) {
showInt(static_cast<T &&>(t));
}
void testTemplate() {
int a = 10;
forwardToShowInt(std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
}
struct Tmp {
Tmp();
Tmp(int &&a);
Tmp(int v1, int &&a);
Tmp(const char *&&s);
Tmp(TriviallyCopyable&& obj);
Tmp(const TriviallyCopyable *&&obj);
void showTmp(TriviallyCopyable&& t);
static void showTmpStatic(TriviallyCopyable&& t);
};
using TmpAlias = Tmp;
void testMethods() {
Tmp t;
int a = 10;
Tmp t1(std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-15]]:13: note: consider changing the 1st parameter of 'Tmp' from 'int &&' to 'const int &'
Tmp t2(a, std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-17]]:21: note: consider changing the 2nd parameter of 'Tmp' from 'int &&' to 'const int &'
const char* s = "";
Tmp t3(std::move(s));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 's' of the trivially-copyable type 'const char *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-20]]:21: note: consider changing the 1st parameter of 'Tmp' from 'const char *&&' to 'const char *'
TriviallyCopyable *obj = new TriviallyCopyable();
Tmp t4(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'TriviallyCopyable' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-23]]:27: note: consider changing the 1st parameter of 'Tmp' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
Tmp t5(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-25]]:34: note: consider changing the 1st parameter of 'Tmp' from 'const TriviallyCopyable *&&' to 'const TriviallyCopyable *'
t.showTmp(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: std::move of the expression of the trivially-copyable type 'TriviallyCopyable' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-27]]:36: note: consider changing the 1st parameter of 'showTmp' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
Tmp::showTmpStatic(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: std::move of the expression of the trivially-copyable type 'TriviallyCopyable' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-29]]:49: note: consider changing the 1st parameter of 'showTmpStatic' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
}
void testMethodsAlias() {
TmpAlias t;
int a = 10;
TmpAlias t1(std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-43]]:13: note: consider changing the 1st parameter of 'Tmp' from 'int &&' to 'const int &'
TmpAlias t2(a, std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-45]]:21: note: consider changing the 2nd parameter of 'Tmp' from 'int &&' to 'const int &'
const char* s = "";
TmpAlias t3(std::move(s));
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: std::move of the variable 's' of the trivially-copyable type 'const char *' has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-48]]:21: note: consider changing the 1st parameter of 'Tmp' from 'const char *&&' to 'const char *'
TrivialAlias *obj = new TrivialAlias();
TmpAlias t4(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: std::move of the expression of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-51]]:27: note: consider changing the 1st parameter of 'Tmp' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
TmpAlias t5(std::move(obj));
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: std::move of the variable 'obj' of the trivially-copyable type 'TrivialAlias *' (aka 'TriviallyCopyable *') has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-53]]:34: note: consider changing the 1st parameter of 'Tmp' from 'const TriviallyCopyable *&&' to 'const TriviallyCopyable *'
t.showTmp(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: std::move of the expression of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-55]]:36: note: consider changing the 1st parameter of 'showTmp' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
TmpAlias::showTmpStatic(std::move(*obj));
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: std::move of the expression of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-57]]:49: note: consider changing the 1st parameter of 'showTmpStatic' from 'TriviallyCopyable &&' to 'const TriviallyCopyable &'
}
void showA(A &&v) {}
void testA() {
A a;
showA(std::move(a));
}
void testAAlias() {
AlsoA a;
showA(std::move(a));
}
void testFuncPointer() {
int a = 10;
void (*choice)(int, int &&);
choice = showInt;
choice(std::move(a), std::move(a));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: choice(a, std::move(a));
// CHECK-MESSAGES: :[[@LINE-3]]:24: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
}
namespace issue_62550 {
struct NonMoveConstructable {
NonMoveConstructable();
NonMoveConstructable(const NonMoveConstructable&);
NonMoveConstructable& operator=(const NonMoveConstructable&);
NonMoveConstructable& operator=(NonMoveConstructable&&);
};
void testNonMoveConstructible() {
NonMoveConstructable t1;
NonMoveConstructable t2{std::move(t1)};
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-11]]:8: note: 'NonMoveConstructable' is not move constructible
}
struct NonMoveAssignable {
NonMoveAssignable();
NonMoveAssignable(const NonMoveAssignable&);
NonMoveAssignable(NonMoveAssignable&&);
NonMoveAssignable& operator=(const NonMoveAssignable&);
};
void testNonMoveAssignable() {
NonMoveAssignable t1;
NonMoveAssignable t2;
t2 = std::move(t1);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-14]]:8: note: 'NonMoveAssignable' is not move assignable
}
struct NonMoveable {
NonMoveable();
NonMoveable(const NonMoveable&);
NonMoveable& operator=(const NonMoveable&);
};
void testNonMoveable() {
NonMoveable t1;
NonMoveable t2{std::move(t1)};
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-10]]:8: note: 'NonMoveable' is not move assignable/constructible
t1 = std::move(t2);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-14]]:8: note: 'NonMoveable' is not move assignable/constructible
}
using AlsoNonMoveable = NonMoveable;
void testAlsoNonMoveable() {
AlsoNonMoveable t1;
AlsoNonMoveable t2{std::move(t1)};
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-23]]:8: note: 'NonMoveable' is not move assignable/constructible
t1 = std::move(t2);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
// CHECK-MESSAGES: :[[@LINE-27]]:8: note: 'NonMoveable' is not move assignable/constructible
}
} // namespace issue_62550
|