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

regression-tests/test-results/clang-12/run-tests-clang-12.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for f in *.cpp
1010
do
1111
let count=count+1
1212
printf "[%s] Starting clang++-12 %s\n" "$count" "$f"
13-
clang++-12 -I../../../include -std=c++20 -pthread -o test.exe $f > $f.output 2>&1
13+
clang++-12 -I../../../include -std=c++20 -pthread -Wunused-parameter -o test.exe $f > $f.output 2>&1
1414
rm -f $f
1515
if test -f "test.exe"; then
1616
let exe_count=exe_count+1

regression-tests/test-results/gcc-13/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

regression-tests/test-results/gcc-13/run-tests-gcc-13.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for f in *.cpp
1010
do
1111
let count=count+1
1212
printf "[%s] Starting gcc 13 %s\n" "$count" "$f"
13-
g++ -I../../../include -std=c++20 -pthread -o test.exe $f > $f.output 2>&1
13+
g++ -I../../../include -std=c++20 -pthread -Wunused-parameter -o test.exe $f > $f.output 2>&1
1414
rm -f $f
1515
if test -f "test.exe"; then
1616
let exe_count=exe_count+1

regression-tests/test-results/mixed-forwarding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ struct X {
2020
};
2121

2222
#line 11 "mixed-forwarding.cpp2"
23-
auto copy_from(auto x) -> void;
23+
auto copy_from([[maybe_unused]] auto param1) -> void;
2424

25-
auto use(auto const& x) -> void;
25+
auto use([[maybe_unused]] auto const& param1) -> void;
2626

2727
// invoking each of these with an rvalue std::pair argument ...
2828
auto apply_implicit_forward(auto&& t) -> void
@@ -46,9 +46,9 @@ CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
4646

4747

4848
#line 11 "mixed-forwarding.cpp2"
49-
auto copy_from(auto x) -> void{}
49+
auto copy_from([[maybe_unused]] auto param1) -> void{}
5050

51-
auto use(auto const& x) -> void{}
51+
auto use([[maybe_unused]] auto const& param1) -> void{}
5252

5353
#line 16 "mixed-forwarding.cpp2"
5454
auto apply_implicit_forward(auto&& t) -> void

regression-tests/test-results/mixed-parameter-passing-with-forward.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include <ctime>
1616

1717
#line 6 "mixed-parameter-passing-with-forward.cpp2"
18-
auto copy_from(auto x) -> void;
18+
auto copy_from([[maybe_unused]] auto param1) -> void;
1919

2020
auto parameter_styles(
21-
cpp2::in<std::string> a, // "in" is default
21+
[[maybe_unused]] cpp2::in<std::string> param1, // "in" is default
2222
std::string b,
23-
std::string& c,
23+
[[maybe_unused]] std::string& param3,
2424
std::string&& d,
2525
auto&& e
2626
) -> void
@@ -36,12 +36,12 @@ CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(e), std::string>)
3636

3737

3838
#line 6 "mixed-parameter-passing-with-forward.cpp2"
39-
auto copy_from(auto x) -> void{}
39+
auto copy_from([[maybe_unused]] auto param1) -> void{}
4040

4141
auto parameter_styles(
42-
cpp2::in<std::string> a,
42+
[[maybe_unused]] cpp2::in<std::string> param1,
4343
std::string b,
44-
std::string& c,
44+
[[maybe_unused]] std::string& param3,
4545
std::string&& d,
4646
auto&& e
4747
) -> void

regression-tests/test-results/mixed-parameter-passing.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include <ctime>
1616

1717
#line 6 "mixed-parameter-passing.cpp2"
18-
auto copy_from(auto x) -> void;
18+
auto copy_from([[maybe_unused]] auto param1) -> void;
1919

2020
auto parameter_styles(
21-
cpp2::in<std::string> a, // "in" is default
21+
[[maybe_unused]] cpp2::in<std::string> param1, // "in" is default
2222
std::string b,
23-
std::string& c,
23+
[[maybe_unused]] std::string& param3,
2424
std::string&& d
2525
) -> void;
2626

@@ -32,12 +32,12 @@ auto parameter_styles(
3232

3333

3434
#line 6 "mixed-parameter-passing.cpp2"
35-
auto copy_from(auto x) -> void{}
35+
auto copy_from([[maybe_unused]] auto param1) -> void{}
3636

3737
auto parameter_styles(
38-
cpp2::in<std::string> a,
38+
[[maybe_unused]] cpp2::in<std::string> param1,
3939
std::string b,
40-
std::string& c,
40+
[[maybe_unused]] std::string& param3,
4141
std::string&& d
4242
) -> void
4343
{

regression-tests/test-results/mixed-postfix-expression-custom-formatting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
#line 2 "mixed-postfix-expression-custom-formatting.cpp2"
14-
auto call(auto const& v, auto const& w, auto const& x, auto const& y, auto const& z) -> void;
14+
auto call([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2, [[maybe_unused]] auto const& param3, [[maybe_unused]] auto const& param4, [[maybe_unused]] auto const& param5) -> void;
1515

1616
[[nodiscard]] auto test(auto const& a) -> std::string;
1717

@@ -24,7 +24,7 @@ auto call(auto const& v, auto const& w, auto const& x, auto const& y, auto const
2424

2525

2626
#line 2 "mixed-postfix-expression-custom-formatting.cpp2"
27-
auto call(auto const& v, auto const& w, auto const& x, auto const& y, auto const& z) -> void{}
27+
auto call([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2, [[maybe_unused]] auto const& param3, [[maybe_unused]] auto const& param4, [[maybe_unused]] auto const& param5) -> void{}
2828

2929
[[nodiscard]] auto test(auto const& a) -> std::string{
3030
return call(a,

regression-tests/test-results/msvc-2022/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

regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class quantity;
1515
#line 1 "pure2-bugfix-for-discard-precedence.cpp2"
1616
class quantity {
1717
private: cpp2::i32 number;
18-
public: explicit quantity(cpp2::in<std::in_place_t> _, cpp2::in<cpp2::i32> x);
18+
public: explicit quantity(cpp2::in<std::in_place_t> i, cpp2::in<cpp2::i32> x);
1919

2020

2121
#line 7 "pure2-bugfix-for-discard-precedence.cpp2"
@@ -35,12 +35,12 @@ auto main() -> int;
3535

3636

3737
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
38-
quantity::quantity(cpp2::in<std::in_place_t> _, cpp2::in<cpp2::i32> x)
38+
quantity::quantity(cpp2::in<std::in_place_t> i, cpp2::in<cpp2::i32> x)
3939
: number{ x }
4040
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
4141
{
4242

43-
static_cast<void>(_);
43+
static_cast<void>(i);
4444
}
4545
auto quantity::operator+=(quantity const& that) -> quantity&{
4646
number += that.number;

regression-tests/test-results/pure2-bugfix-for-memberwise-base-assignment.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ class Derived;
1919
#line 1 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
2020
class Base {
2121
public: explicit Base();
22-
public: Base(Base const& that);
22+
public: Base([[maybe_unused]] Base const& that);
2323

2424
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
25-
public: auto operator=(Base const& that) -> Base& ;
25+
public: auto operator=([[maybe_unused]] Base const& that) -> Base& ;
2626

2727
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
28-
public: Base(Base&& that) noexcept;
28+
public: Base([[maybe_unused]] Base&& that) noexcept;
2929

3030
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
31-
public: auto operator=(Base&& that) noexcept -> Base& ;
32-
public: Base(auto const& x);
31+
public: auto operator=([[maybe_unused]] Base&& that) noexcept -> Base& ;
32+
public: Base([[maybe_unused]] auto const& param2);
3333
#line 4 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
34-
public: auto operator=(auto const& x) -> Base& ;
34+
public: auto operator=([[maybe_unused]] auto const& param2) -> Base& ;
3535
};
3636

3737
class Derived: public Base {
@@ -49,22 +49,22 @@ auto main() -> int;
4949

5050
#line 2 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
5151
Base::Base(){}
52-
Base::Base (Base const& that) { std::cout << "(out this, that)\n"; }
52+
Base::Base ([[maybe_unused]] Base const& that) { std::cout << "(out this, that)\n"; }
5353
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
54-
auto Base::operator=(Base const& that) -> Base& { std::cout << "(out this, that)\n";
54+
auto Base::operator=([[maybe_unused]] Base const& that) -> Base& { std::cout << "(out this, that)\n";
5555
return *this;
5656
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
5757
}
5858
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
59-
Base::Base (Base&& that) noexcept { std::cout << "(out this, that)\n"; }
59+
Base::Base ([[maybe_unused]] Base&& that) noexcept { std::cout << "(out this, that)\n"; }
6060
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
61-
auto Base::operator=(Base&& that) noexcept -> Base& { std::cout << "(out this, that)\n";
61+
auto Base::operator=([[maybe_unused]] Base&& that) noexcept -> Base& { std::cout << "(out this, that)\n";
6262
return *this;
6363
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
6464
}
65-
Base::Base(auto const& x) { std::cout << "(implicit out this, x)\n"; }
65+
Base::Base([[maybe_unused]] auto const& param2) { std::cout << "(implicit out this, _)\n"; }
6666
#line 4 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
67-
auto Base::operator=(auto const& x) -> Base& { std::cout << "(implicit out this, x)\n";
67+
auto Base::operator=([[maybe_unused]] auto const& param2) -> Base& { std::cout << "(implicit out this, _)\n";
6868
return *this;
6969
#line 4 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
7070
}

regression-tests/test-results/pure2-types-basics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ namespace N {
138138

139139
myclass::myclass(cpp2::in<int> x, cpp2::in<std::string> s)
140140
: data{ 77 }
141-
, more{ s + " plugh" }
141+
, more{ s + std::to_string(x) + " plugh" }
142142
#line 20 "pure2-types-basics.cpp2"
143143
{
144144

regression-tests/test-results/pure2-types-inheritance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public: virtual ~Human() noexcept;
3939

4040
namespace N {
4141
template<int I> class Machine {
42-
public: explicit Machine(cpp2::in<std::string> id);
42+
public: explicit Machine([[maybe_unused]] cpp2::in<std::string> param2);
4343
public: virtual auto work() const -> void = 0;
4444

4545
public: virtual ~Machine() noexcept;
@@ -97,7 +97,7 @@ auto main() -> int;
9797
#line 6 "pure2-types-inheritance.cpp2"
9898
namespace N {
9999

100-
template <int I> Machine<I>::Machine(cpp2::in<std::string> id){}
100+
template <int I> Machine<I>::Machine([[maybe_unused]] cpp2::in<std::string> param2){}
101101

102102
template <int I> Machine<I>::~Machine() noexcept{}
103103

regression-tests/test-results/pure2-ufcs-member-access-and-chaining.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
#line 24 "pure2-ufcs-member-access-and-chaining.cpp2"
18-
auto no_return(cpp2::in<int> x) -> void;
18+
auto no_return([[maybe_unused]] auto const& param1) -> void;
1919

2020
[[nodiscard]] auto ufcs(cpp2::in<int> i) -> int;
2121
struct fun__ret { int i; };
@@ -32,7 +32,7 @@ auto no_return(cpp2::in<int> x) -> void;
3232

3333
#line 39 "pure2-ufcs-member-access-and-chaining.cpp2"
3434
// And a test for non-local UFCS, which shouldn't do a [&] capture
35-
[[nodiscard]] auto f(auto const& x) -> int;
35+
[[nodiscard]] auto f([[maybe_unused]] auto const& param1) -> int;
3636
extern int y;
3737

3838
//=== Cpp2 function definitions =================================================
@@ -61,7 +61,7 @@ extern int y;
6161
CPP2_UFCS_0(no_return, 42);
6262
}
6363

64-
auto no_return(cpp2::in<int> x) -> void{}
64+
auto no_return([[maybe_unused]] auto const& param1) -> void{}
6565

6666
[[nodiscard]] auto ufcs(cpp2::in<int> i) -> int{
6767
return i + 2;
@@ -79,6 +79,6 @@ auto no_return(cpp2::in<int> x) -> void{}
7979
}
8080

8181
#line 40 "pure2-ufcs-member-access-and-chaining.cpp2"
82-
[[nodiscard]] auto f(auto const& x) -> int { return 0; }
82+
[[nodiscard]] auto f([[maybe_unused]] auto const& param1) -> int { return 0; }
8383
int y {CPP2_UFCS_0_NONLOCAL(f, 0)};
8484

0 commit comments

Comments
 (0)