performance-no-automatic-move.cpp
1.8 KB
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
// RUN: %check_clang_tidy -std=c++11,c++14,c++17,c++2a %s performance-no-automatic-move %t
struct Obj {
Obj();
Obj(const Obj &);
Obj(Obj &&);
virtual ~Obj();
};
template <typename T>
struct StatusOr {
StatusOr(const T &);
StatusOr(T &&);
};
struct NonTemplate {
NonTemplate(const Obj &);
NonTemplate(Obj &&);
};
template <typename T>
T Make();
StatusOr<Obj> PositiveStatusOrConstValue() {
const Obj obj = Make<Obj>();
return obj;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
}
NonTemplate PositiveNonTemplateConstValue() {
const Obj obj = Make<Obj>();
return obj;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
}
Obj PositiveSelfConstValue() {
const Obj obj = Make<Obj>();
return obj;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
}
// FIXME: Ideally we would warn here too.
NonTemplate PositiveNonTemplateLifetimeExtension() {
const Obj &obj = Make<Obj>();
return obj;
}
// FIXME: Ideally we would warn here too.
StatusOr<Obj> PositiveStatusOrLifetimeExtension() {
const Obj &obj = Make<Obj>();
return obj;
}
// Negatives.
StatusOr<Obj> Temporary() {
return Make<const Obj>();
}
StatusOr<Obj> ConstTemporary() {
return Make<const Obj>();
}
StatusOr<Obj> Nrvo() {
Obj obj = Make<Obj>();
return obj;
}
StatusOr<Obj> Ref() {
Obj &obj = Make<Obj &>();
return obj;
}
StatusOr<Obj> ConstRef() {
const Obj &obj = Make<Obj &>();
return obj;
}
const Obj global;
StatusOr<Obj> Global() {
return global;
}
struct FromConstRefOnly {
FromConstRefOnly(const Obj &);
};
FromConstRefOnly FromConstRefOnly() {
const Obj obj = Make<Obj>();
return obj;
}