Skip to content

Commit a1eed75

Browse files
committed
add test.cpp for A0-1-4
1 parent b1e204d commit a1eed75

File tree

1 file changed

+26
-13
lines changed
  • cpp/common/test/rules/unusedparameter

1 file changed

+26
-13
lines changed

cpp/common/test/rules/unusedparameter/test.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,29 @@ class A {
1818
virtual void d(int x, int y) {} // virtual, not covered by this rule
1919
};
2020

21-
void f(
22-
int i,
23-
int j,
24-
int k,
25-
[[maybe_unused]]
26-
int l // NON_COMPILANT: maybe_unused parameters should also be considered unused
27-
) {
28-
static_cast<void>(i); // NON_COMPILANT: static_cast to void should also be considered unused
29-
(void)j; // NON_COMPILANT: C-style void casts should also be considered unused
30-
std::ignore = k; // NON_COMPILANT: Assignment to std::ignore should also be considered unused
31-
}
32-
33-
void test_no_def(int x); // COMPLIANT - no definition, so cannot be "unused"
21+
void f(
22+
int i, // COMPLIANT
23+
int j, // COMPLIANT
24+
int k, // COMPLIANT
25+
[[maybe_unused]] int l // COMPLIANT: explicitly stated as [[maybe_unused]]
26+
) {
27+
static_cast<void>(i); // COMPLIANT: explicitly ignored by static_cast to void
28+
(void)j; // COMPLIANT: explicitly ignored by c-style cast to void
29+
std::ignore = k; // COMPLIANT: explicitly ignored by assignment to std::ignore
30+
}
31+
32+
void test_lambda_expr() {
33+
auto lambda =
34+
[](int x, // COMPLIANT: used
35+
int y, // NON_COMPLIANT: unused without explicit notice
36+
[[maybe_unused]] int z, // COMPLIANT: stdattribute [[maybe_unused]]
37+
int w, // COMPLIANT: static_cast to void
38+
int u, // COMPLIANT: c-style cast to void
39+
int) { // COMPLIANT: unnamed parameter
40+
static_cast<void>(w);
41+
(void)u;
42+
return x;
43+
};
44+
}
45+
46+
void test_no_def(int x); // COMPLIANT - no definition, so cannot be "unused"

0 commit comments

Comments
 (0)