File: noexcept-swap.cpp

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (203 lines) | stat: -rw-r--r-- 6,349 bytes parent folder | download | duplicates (2)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// RUN: %check_clang_tidy %s performance-noexcept-swap %t -- -- -fexceptions

void throwing_function() noexcept(false);
void noexcept_function() noexcept;

template <typename>
struct TemplateNoexceptWithInt {
  static void f() {}
};

template <>
struct TemplateNoexceptWithInt<int> {
  static void f() noexcept {}
};

class A {
  void swap(A &);
  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: swap functions should be marked noexcept [performance-noexcept-swap]
  // CHECK-FIXES: void swap(A &) noexcept ;
};

void swap(A &, A &);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(A &, A &) noexcept ;

struct B {
  static constexpr bool kFalse = false;
  void swap(B &) noexcept(kFalse);
  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};

void swap(B &, B &) noexcept(B::kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]

template <typename>
struct C {
  void swap(C&);
  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: swap functions should be marked noexcept [performance-noexcept-swap]
  // CHECK-FIXES: void swap(C&) noexcept ;
};

template <typename T>
void swap(C<T>&, C<T>&);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(C<T>&, C<T>&) noexcept ;
void swap(C<int>&, C<int>&);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
// CHECK-FIXES: void swap(C<int>&, C<int>&) noexcept ;

template <typename>
struct D {
  static constexpr bool kFalse = false;
  void swap(D &) noexcept(kFalse);
  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};

template <typename T>
void swap(D<T> &, D<T> &) noexcept(D<T>::kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
void swap(D<int> &, D<int> &) noexcept(D<int>::kFalse);
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]

struct E {
  void swap(E &) noexcept(noexcept(throwing_function()));
  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};

void swap(E &, E &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]

template <typename>
struct F {
  void swap(F &) noexcept(noexcept(throwing_function()));
  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};

template <typename T>
void swap(F<T> &, F<T> &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
void swap(F<int> &, F<int> &) noexcept(noexcept(throwing_function()));
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]

struct G {
  void swap(G &) noexcept(noexcept(TemplateNoexceptWithInt<double>::f()));
  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]
};

void swap(G &, G &) noexcept(noexcept(TemplateNoexceptWithInt<double>::f()));
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap]

class OK {};

struct OK1 {
  void swap(OK1 &) noexcept;
};

void swap(OK1 &, OK1 &) noexcept;

struct OK2 {
  static constexpr bool kTrue = true;
  void swap(OK2 &) noexcept(kTrue) {}
};

void swap(OK2 &, OK2 &) noexcept(OK2::kTrue);

struct OK3 {
    void swap(OK3 &) = delete;
};

void swap(OK3 &, OK3 &) = delete;

struct OK4 {
  void swap(OK4 &) noexcept(false);
};

void swap(OK4 &, OK4 &) noexcept(false);

struct OK5 {
  void swap(OK5 &) noexcept(true);
};

void swap(OK5 &, OK5 &)noexcept(true);

struct OK12 {
  void swap(OK12 &) noexcept(noexcept(noexcept_function()));
};

void swap(OK12 &, OK12 &) noexcept(noexcept(noexcept_function()));

struct OK13 {
  void swap(OK13 &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
};

void swap(OK13 &, OK13 &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));

template <typename>
class OK14 {};

template <typename>
struct OK15 {
  void swap(OK15 &) noexcept;
};

template <typename T>
void swap(OK15<T> &, OK15<T> &) noexcept;
void swap(OK15<int> &, OK15<int> &) noexcept;

template <typename>
struct OK16 {
  static constexpr bool kTrue = true;
  void swap(OK16 &) noexcept(kTrue);
};

// FIXME: This gives a warning, but it should be OK.
//template <typename T>
//void swap(OK16<T> &, OK16<T> &) noexcept(OK16<T>::kTrue);
template <typename T>
void swap(OK16<int> &, OK16<int> &) noexcept(OK16<int>::kTrue);

template <typename>
struct OK17 {
    void swap(OK17 &) = delete;
};

template <typename T>
void swap(OK17<T> &, OK17<T> &) = delete;
void swap(OK17<int> &, OK17<int> &) = delete;

template <typename>
struct OK18 {
  void swap(OK18 &) noexcept(false);
};

template <typename T>
void swap(OK18<T> &, OK18<T> &) noexcept(false);
void swap(OK18<int> &, OK18<int> &) noexcept(false);

template <typename>
struct OK19 {
  void swap(OK19 &) noexcept(true);
};

template <typename T>
void swap(OK19<T> &, OK19<T> &)noexcept(true);
void swap(OK19<int> &, OK19<int> &)noexcept(true);

template <typename>
struct OK20 {
  void swap(OK20 &) noexcept(noexcept(noexcept_function()));
};

template <typename T>
void swap(OK20<T> &, OK20<T> &) noexcept(noexcept(noexcept_function()));
void swap(OK20<int> &, OK20<int> &) noexcept(noexcept(noexcept_function()));

template <typename>
struct OK21 {
  void swap(OK21 &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
};

template <typename T>
void swap(OK21<T> &, OK21<T> &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));
void swap(OK21<int> &, OK21<int> &) noexcept(noexcept(TemplateNoexceptWithInt<int>::f()));