Skip to content

Commit 6ce2643

Browse files
committed
Make output -Wunused-parameter-clean, and add real support for _ unnamed parameters, closes #560
Emit `[[maybe_unused]]` on a `that` parameter if the class is empty. Add -Wunused-parameter to my GCC and Clang regression tests. Add `_` unnamed parameter support, and use ordinals instead of line/col numbers to keep the generated names stable. As an example from one of the updated regression tests that had a helper function to just accept (but not use) five generic parameters, that function is now just: `call: (_, _, _, _, _) = { }`
1 parent 62dfdcb commit 6ce2643

27 files changed

+85
-64
lines changed

regression-tests/mixed-forwarding.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ struct X {
88
X(X && that) : i{that.i} { std::cout << "move X " << i << "\n"; }
99
};
1010

11-
copy_from: (copy x:_) = { }
11+
copy_from: (copy _) = { }
1212

13-
use: (x:_) = {}
13+
use: (_) = {}
1414

1515
// invoking each of these with an rvalue std::pair argument ...
1616
apply_implicit_forward: (forward t: std::pair<X, X>) = {

regression-tests/mixed-parameter-passing-with-forward.cpp2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <cstdlib>
44
#include <ctime>
55

6-
copy_from: (copy x:_) = { }
6+
copy_from: (copy _) = { }
77

88
parameter_styles: (
9-
in a: std::string, // "in" is default
9+
in _: std::string, // "in" is default
1010
copy b: std::string,
11-
inout c: std::string,
11+
inout _: std::string,
1212
move d: std::string,
1313
forward e: std::string
1414
)

regression-tests/mixed-parameter-passing.cpp2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <cstdlib>
44
#include <ctime>
55

6-
copy_from: (copy x:_) = { }
6+
copy_from: (copy _) = { }
77

88
parameter_styles: (
9-
in a: std::string, // "in" is default
9+
in _: std::string, // "in" is default
1010
copy b: std::string,
11-
inout c: std::string,
11+
inout _: std::string,
1212
move d: std::string
1313
)
1414
= {

regression-tests/mixed-postfix-expression-custom-formatting.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
call: (v:_, w:_, x:_, y:_, z:_) = { }
2+
call: (_, _, _, _, _) = { }
33

44
test: (a:_) -> std::string = {
55
return call( a,

regression-tests/pure2-bugfix-for-discard-precedence.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
quantity: type = {
22
number: i32;
3-
operator=: (out this, _: std::in_place_t, x: i32) = {
3+
operator=: (out this, i: std::in_place_t, x: i32) = {
44
number = x;
5-
_ = _;
5+
_ = i;
66
}
77
operator+=: (inout this, that) -> forward quantity = {
88
number += that.number;

regression-tests/pure2-bugfix-for-memberwise-base-assignment.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Base: type = {
22
operator=: (out this) = { }
33
operator=: (out this, that) = std::cout << "(out this, that)\n";
4-
operator=: (implicit out this, x) = std::cout << "(implicit out this, x)\n";
4+
operator=: (implicit out this, _) = std::cout << "(implicit out this, _)\n";
55
}
66

77
Derived: type = {

regression-tests/pure2-types-basics.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ myclass : type = {
1919

2020
operator=: (out this, x: int, s: std::string) = {
2121
this.data = 77;
22-
this.more = s + " plugh";
22+
this.more = s + std::to_string(x) + " plugh";
2323
std::cout << "myclass: from int and string\n";
2424
print();
2525
}

regression-tests/pure2-types-inheritance.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Human: @interface type = {
55

66
N: namespace = {
77
Machine: @polymorphic_base <I:int> type = {
8-
operator=: (out this, id: std::string) = {}
8+
operator=: (out this, _: std::string) = {}
99
work: (virtual this);
1010
}
1111
}

regression-tests/pure2-ufcs-member-access-and-chaining.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ main: () -> int = {
2121
42.no_return();
2222
}
2323

24-
no_return: (x: int) = { }
24+
no_return: (_) = { }
2525

2626
ufcs: (i:int) -> int = {
2727
return i+2;
@@ -37,5 +37,5 @@ get_i: (r:_) -> int = {
3737
}
3838

3939
// And a test for non-local UFCS, which shouldn't do a [&] capture
40-
f: (x)->int = 0;
40+
f: (_)->int = 0;
4141
y: int = 0.f();

regression-tests/test-results/clang-12/pure2-types-basics.cpp.execution

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ myclass: explicit from string
1111
myclass: default
1212
data: 504, more: 3.141590
1313
myclass: from int and string
14-
data: 77, more: hair plugh
14+
data: 77, more: hair1 plugh
1515
x's state before assignments: data: 1, more: 504
1616
myclass: implicit from int
1717
data: 84, more: 504

0 commit comments

Comments
 (0)