Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2aed0f1

Browse files
committed
Add const-but-mutable pointer examples
1 parent87a5158 commit2aed0f1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎cpp/misra/test/rules/RULE-9-5-1/test.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ void f1(int &x) {} // Function that takes a non-const integer reference
66
voidg1(int *x) {}// Function that takes a non-const integer pointer
77
voidf2(constint &x) {}// Function that takes a non-const integer reference
88
voidg2(constint *x) {}// Function that takes a non-const integer pointer
9+
voidf3(int *const x) {}
910

1011
inth1() {return1; }
1112
constexprinth2() {return1; }
@@ -198,6 +199,11 @@ int main() {
198199
constint *m = &i;
199200
}
200201

202+
for (int i = j; i < k; i += l) {// NON-COMPLIANT: The loop counter is taken
203+
// as a const but mutable pointer
204+
int *const m = &i;
205+
}
206+
201207
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop bound is taken as
202208
// a non-const reference
203209
int &m = k;
@@ -218,6 +224,11 @@ int main() {
218224
constint *m = &k;
219225
}
220226

227+
for (int i = j; i < k; i += l) {// NON-COMPLIANT: The loop bound is taken as
228+
// a const but mutable pointer
229+
int *const m = &k;
230+
}
231+
221232
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop step is taken as
222233
// a non-const reference
223234
int &m = l;
@@ -238,6 +249,11 @@ int main() {
238249
constint *m = &l;
239250
}
240251

252+
for (int i = j; i < k; i += l) {// NON-COMPLIANT: The loop step is taken as
253+
// a const but mutable pointer
254+
int *const m = &l;
255+
}
256+
241257
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop counter is passed
242258
// to a non-const reference parameter
243259
f1(i);
@@ -258,6 +274,11 @@ int main() {
258274
g2(&i);
259275
}
260276

277+
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop counter is passed
278+
// to a const but mutable pointer parameter
279+
f3(&i);
280+
}
281+
261282
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop bound is passed to
262283
// a non-const reference parameter
263284
f1(k);
@@ -279,6 +300,11 @@ int main() {
279300
g2(&k);
280301
}
281302

303+
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop bound is passed to
304+
// a const but mutable pointer parameter
305+
f3(&k);
306+
}
307+
282308
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop step is passed to
283309
// a non-const reference parameter
284310
f1(l);
@@ -298,4 +324,9 @@ int main() {
298324
// a const pointer parameter
299325
g2(&l);
300326
}
327+
328+
for (int i = j; i < k; i += l) {// NON_COMPLIANT: The loop step is passed to
329+
// a const but mutable pointer parameter
330+
f3(&l);
331+
}
301332
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp