// RUN: %check_clang_tidy -std=c++11-or-later %s performance-no-automatic-move %t struct Obj { Obj(); Obj(const Obj &); Obj(Obj &&); virtual ~Obj(); }; struct NonTemplate { NonTemplate(const Obj &); NonTemplate(Obj &&); }; template struct TemplateCtorPair { TemplateCtorPair(const T &); TemplateCtorPair(T &&value); }; template struct UrefCtor { template UrefCtor(U &&value); }; template T Make(); NonTemplate PositiveNonTemplate() { const Obj obj = Make(); return obj; // selects `NonTemplate(const Obj&)` // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents // automatic move [performance-no-automatic-move] } TemplateCtorPair PositiveTemplateCtorPair() { const Obj obj = Make(); return obj; // selects `TemplateCtorPair(const T&)` // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents // automatic move [performance-no-automatic-move] } UrefCtor PositiveUrefCtor() { const Obj obj = Make(); return obj; // selects `UrefCtor(const T&&)` // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents // automatic move [performance-no-automatic-move] } Obj PositiveCantNrvo(bool b) { const Obj obj1; const Obj obj2; if (b) { return obj1; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: constness of 'obj1' prevents automatic move [performance-no-automatic-move] } return obj2; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj2' prevents automatic move [performance-no-automatic-move] } // FIXME: Ideally we would warn here too. NonTemplate PositiveNonTemplateLifetimeExtension() { const Obj &obj = Make(); return obj; } // FIXME: Ideally we would warn here too. UrefCtor PositiveUrefCtorLifetimeExtension() { const Obj &obj = Make(); return obj; } // Negatives. UrefCtor Temporary() { return Make(); } UrefCtor ConstTemporary() { return Make(); } UrefCtor ConvertingMoveConstructor() { Obj obj = Make(); return obj; } Obj ConstNrvo() { const Obj obj = Make(); return obj; } Obj NotNrvo(bool b) { Obj obj1; Obj obj2; if (b) { return obj1; } return obj2; } UrefCtor Ref() { Obj &obj = Make(); return obj; } UrefCtor ConstRef() { const Obj &obj = Make(); return obj; } const Obj global; UrefCtor Global() { return global; } struct FromConstRefOnly { FromConstRefOnly(const Obj &); }; FromConstRefOnly FromConstRefOnly() { const Obj obj = Make(); return obj; }