1 // RUN: %check_clang_tidy -std=c++11-or-later %s performance-no-automatic-move %t 2 3 struct Obj { 4 Obj(); 5 Obj(const Obj &); 6 Obj(Obj &&); 7 virtual ~Obj(); 8 }; 9 10 template <typename T> 11 struct StatusOr { 12 StatusOr(const T &); 13 StatusOr(T &&); 14 }; 15 16 struct NonTemplate { 17 NonTemplate(const Obj &); 18 NonTemplate(Obj &&); 19 }; 20 21 template <typename T> 22 T Make(); 23 PositiveStatusOrConstValue()24StatusOr<Obj> PositiveStatusOrConstValue() { 25 const Obj obj = Make<Obj>(); 26 return obj; 27 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move] 28 } 29 PositiveNonTemplateConstValue()30NonTemplate PositiveNonTemplateConstValue() { 31 const Obj obj = Make<Obj>(); 32 return obj; 33 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move] 34 } 35 PositiveSelfConstValue()36Obj PositiveSelfConstValue() { 37 const Obj obj = Make<Obj>(); 38 return obj; 39 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move] 40 } 41 42 // FIXME: Ideally we would warn here too. PositiveNonTemplateLifetimeExtension()43NonTemplate PositiveNonTemplateLifetimeExtension() { 44 const Obj &obj = Make<Obj>(); 45 return obj; 46 } 47 48 // FIXME: Ideally we would warn here too. PositiveStatusOrLifetimeExtension()49StatusOr<Obj> PositiveStatusOrLifetimeExtension() { 50 const Obj &obj = Make<Obj>(); 51 return obj; 52 } 53 54 // Negatives. 55 Temporary()56StatusOr<Obj> Temporary() { 57 return Make<const Obj>(); 58 } 59 ConstTemporary()60StatusOr<Obj> ConstTemporary() { 61 return Make<const Obj>(); 62 } 63 Nrvo()64StatusOr<Obj> Nrvo() { 65 Obj obj = Make<Obj>(); 66 return obj; 67 } 68 Ref()69StatusOr<Obj> Ref() { 70 Obj &obj = Make<Obj &>(); 71 return obj; 72 } 73 ConstRef()74StatusOr<Obj> ConstRef() { 75 const Obj &obj = Make<Obj &>(); 76 return obj; 77 } 78 79 const Obj global; 80 Global()81StatusOr<Obj> Global() { 82 return global; 83 } 84 85 struct FromConstRefOnly { 86 FromConstRefOnly(const Obj &); 87 }; 88 FromConstRefOnly()89FromConstRefOnly FromConstRefOnly() { 90 const Obj obj = Make<Obj>(); 91 return obj; 92 } 93