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
|
// RUN: %check_clang_tidy %s cert-dcl21-cpp %t
class A {};
A operator++(A &, int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a non-constant object instead of a constant object type [cert-dcl21-cpp]
// CHECK-FIXES: {{^}}const A operator++(A &, int);
A operator--(A &, int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a no
// CHECK-FIXES: {{^}}const A operator--(A &, int);
class B {};
B &operator++(B &);
const B operator++(B &, int);
B &operator--(B &);
const B operator--(B &, int);
class D {
D &operator++();
const D operator++(int);
D &operator--();
const D operator--(int);
};
class C {
C operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a no
// CHECK-FIXES: {{^}}const C operator++(int);
C operator--(int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a no
// CHECK-FIXES: {{^}}const C operator--(int);
};
class E {};
E &operator++(E &, int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a reference instead of a constant object type [cert-dcl21-cpp]
// CHECK-FIXES: {{^}}const E operator++(E &, int);
E &operator--(E &, int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a re
// CHECK-FIXES: {{^}}const E operator--(E &, int);
class G {
G &operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}}const G operator++(int);
G &operator--(int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator--' returns a re
// CHECK-FIXES: {{^}}const G operator--(int);
};
class F {};
const F &operator++(F &, int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}}const F operator++(F &, int);
const F &operator--(F &, int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
// CHECK-FIXES: {{^}}const F operator--(F &, int);
class H {
const H &operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}}const H operator++(int);
const H &operator--(int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
// CHECK-FIXES: {{^}}const H operator--(int);
};
#define FROM_MACRO P&
class P {
const FROM_MACRO operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}}const FROM_MACRO operator++(int);
};
template<typename T>
class Q {
const Q &operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}}const Q<T> operator++(int);
const Q &operator--(int);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: overloaded 'operator--' returns a re
// CHECK-FIXES: {{^}}const Q<T> operator--(int);
};
void foobar() {
Q<int> a;
Q<float> b;
(void)a;
(void)b;
}
struct S {};
typedef S& SRef;
SRef operator++(SRef, int);
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}}SRef operator++(SRef, int);
struct T {
typedef T& TRef;
TRef operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}} TRef operator++(int);
};
struct U {
typedef const U& ConstURef;
ConstURef& operator++(int);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: overloaded 'operator++' returns a re
// CHECK-FIXES: {{^}} ConstURef& operator++(int);
};
struct V {
V *operator++(int);
V *const operator--(int);
};
|