1 // RUN: %check_clang_tidy %s cert-dcl21-cpp %t
2
3 class A {};
4
5 A operator++(A &, int);
6 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a non-constant object instead of a constant object type [cert-dcl21-cpp]
7 // CHECK-FIXES: {{^}}const A operator++(A &, int);
8
9 A operator--(A &, int);
10 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a no
11 // CHECK-FIXES: {{^}}const A operator--(A &, int);
12
13 class B {};
14
15 B &operator++(B &);
16 const B operator++(B &, int);
17
18 B &operator--(B &);
19 const B operator--(B &, int);
20
21
22 class D {
23 D &operator++();
24 const D operator++(int);
25
26 D &operator--();
27 const D operator--(int);
28 };
29
30 class C {
31 C operator++(int);
32 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a no
33 // CHECK-FIXES: {{^}}const C operator++(int);
34
35 C operator--(int);
36 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a no
37 // CHECK-FIXES: {{^}}const C operator--(int);
38 };
39
40 class E {};
41
42 E &operator++(E &, int);
43 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a reference instead of a constant object type [cert-dcl21-cpp]
44 // CHECK-FIXES: {{^}}const E operator++(E &, int);
45
46 E &operator--(E &, int);
47 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a re
48 // CHECK-FIXES: {{^}}const E operator--(E &, int);
49
50 class G {
51 G &operator++(int);
52 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a re
53 // CHECK-FIXES: {{^}}const G operator++(int);
54
55 G &operator--(int);
56 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a re
57 // CHECK-FIXES: {{^}}const G operator--(int);
58 };
59
60 class F {};
61
62 const F &operator++(F &, int);
63 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
64 // CHECK-FIXES: {{^}}const F operator++(F &, int);
65
66 const F &operator--(F &, int);
67 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
68 // CHECK-FIXES: {{^}}const F operator--(F &, int);
69
70 class H {
71 const H &operator++(int);
72 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
73 // CHECK-FIXES: {{^}}const H operator++(int);
74
75 const H &operator--(int);
76 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
77 // CHECK-FIXES: {{^}}const H operator--(int);
78 };
79
80
81 #define FROM_MACRO P&
82 class P {
83 const FROM_MACRO operator++(int);
84 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
85 // CHECK-FIXES: {{^}}const FROM_MACRO operator++(int);
86 };
87
88
89 template<typename T>
90 class Q {
91 const Q &operator++(int);
92 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
93 // CHECK-FIXES: {{^}}const Q<T> operator++(int);
94
95 const Q &operator--(int);
96 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
97 // CHECK-FIXES: {{^}}const Q<T> operator--(int);
98 };
99
foobar()100 void foobar() {
101 Q<int> a;
102 Q<float> b;
103 (void)a;
104 (void)b;
105 }
106
107 struct S {};
108 typedef S& SRef;
109
110 SRef operator++(SRef, int);
111 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a re
112 // CHECK-FIXES: {{^}}SRef operator++(SRef, int);
113
114 struct T {
115 typedef T& TRef;
116
117 TRef operator++(int);
118 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: overloaded 'operator++' returns a re
119 // CHECK-FIXES: {{^}} TRef operator++(int);
120 };
121
122 struct U {
123 typedef const U& ConstURef;
124
125 ConstURef& operator++(int);
126 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: overloaded 'operator++' returns a re
127 // CHECK-FIXES: {{^}} ConstURef& operator++(int);
128 };
129
130 struct V {
131 V *operator++(int);
132 V *const operator--(int);
133 };
134
135