Skip to content

Commit d0986ee

Browse files
committed
test: discard unused parameters but not void expressions
1 parent e3ad1b5 commit d0986ee

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Dependent, non-deducible parameters
2-
// are wrapped like non-dependent parameters.
1+
// Dependent, non-deducible parameters are wrapped like non-dependent parameters.
32
init: <T> (out x: std::integral_constant<i32, T::value>) = { x = (); }
43
init: <T> (out x: std::integral_constant<i32, T::value>, _: T) = { x = (); }
54
id: <T> (x: std::integral_constant<i32, T::value>) -> forward _ = x;
@@ -13,21 +12,21 @@ main: () = {
1312
assert(id<zero>(z)& == z&);
1413

1514
// Deducible parameters.
16-
_ = :v = 0;
17-
_ = :<T> (x: std::vector<T>) = {}(:std::vector<i32> = ());
18-
_ = :<T> (x: std::vector<std::vector<T>>) = {}(:std::vector<std::vector<i32>> = ());
15+
_ = :v = 0;
16+
:<T> (_: std::vector<T>) = {}(:std::vector<i32> = ());
17+
:<T> (_: std::vector<std::vector<T>>) = {}(:std::vector<std::vector<i32>> = ());
1918
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z); // Blocked on #727.
20-
_ = :<T, U> (x: std::array<T, U::value>, y: U) = {}(:std::array<i32, 0> = (), z);
19+
:<T, U> (_: std::array<T, U::value>, _: U) = {}(:std::array<i32, 0> = (), z);
2120
init(out z, z);
2221
id(z, z);
2322

2423
// Test that these are emitted unwrapped in case they are deducible.
25-
(copy f := :<T> (x: std::vector<std::type_identity_t<T>>) = {})
24+
(copy f := :<T> (_: std::vector<std::type_identity_t<T>>) = {})
2625
static_assert(!std::is_invocable_v<decltype(f), std::vector<i32>>, "`T` is non-deducible.");
27-
(copy f := :<T> (x: std::vector<std::vector<T>>) = {})
26+
(copy f := :<T> (_: std::vector<std::vector<T>>) = {})
2827
static_assert(std::is_invocable_v<decltype(f), std::vector<std::vector<i32>>>, "`T` is deducible.");
2928
}
3029

3130
v: <T> type = {
32-
operator=: (out this, x: T) = { }
31+
operator=: (out this, _: T) = { }
3332
}

regression-tests/pure2-bugfix-for-dependent-types.cpp2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ main: () = {
7070
_ = :() = { _ = :() = { _ = :<T> () = { _ = :() = { _ = :T::value_type = (); }; }; }; };
7171
_ = :() = { _ = :<T> () = { _ = :() = { _ = :() = { _ = :T::value_type = (); }; }; }; };
7272
_ = :<T> () = { _ = :() = { _ = :() = { _ = :() = { _ = :T::value_type = (); }; }; }; };
73-
_ = :<T> () = { _ = :() = { _ = :() = { _ = :(x: T::value_type) = {}; }; }; };
74-
_ = :<T> () = { _ = :() = { _ = :(x: T::value_type) = { _ = :() = {}; }; }; };
75-
_ = :<T> () = { _ = :(x: T::value_type) = { _ = :() = { _ = :() = {}; }; }; };
76-
_ = :<T> (x: T::value_type) = { _ = :() = { _ = :() = { _ = :() = {}; }; }; };
73+
_ = :<T> () = { _ = :() = { _ = :() = { _ = :(_: T::value_type) = {}; }; }; };
74+
_ = :<T> () = { _ = :() = { _ = :(_: T::value_type) = { _ = :() = {}; }; }; };
75+
_ = :<T> () = { _ = :(_: T::value_type) = { _ = :() = { _ = :() = {}; }; }; };
76+
_ = :<T> (_: T::value_type) = { _ = :() = { _ = :() = { _ = :() = {}; }; }; };
7777

7878
// Lookup.
7979
{

regression-tests/test-results/pure2-bugfix-for-deducible-parameters.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,39 @@
88

99
#line 1 "pure2-bugfix-for-deducible-parameters.cpp2"
1010

11-
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
11+
#line 30 "pure2-bugfix-for-deducible-parameters.cpp2"
1212
template<typename T> class v;
1313

1414

1515
//=== Cpp2 type definitions and function declarations ===========================
1616

1717
#line 1 "pure2-bugfix-for-deducible-parameters.cpp2"
18-
// Dependent, non-deducible parameters
19-
// are wrapped like non-dependent parameters.
20-
#line 3 "pure2-bugfix-for-deducible-parameters.cpp2"
18+
// Dependent, non-deducible parameters are wrapped like non-dependent parameters.
19+
#line 2 "pure2-bugfix-for-deducible-parameters.cpp2"
2120
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void;
2221
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, [[maybe_unused]] T const& unnamed_param_2) -> void;
2322
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&&;
2423
template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void;
2524

2625
auto main() -> int;
2726

28-
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
27+
#line 30 "pure2-bugfix-for-deducible-parameters.cpp2"
2928
template<typename T> class v {
30-
public: explicit v(T const& x);
31-
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
32-
public: auto operator=(T const& x) -> v& ;
29+
public: explicit v([[maybe_unused]] T const& unnamed_param_2);
30+
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
31+
public: auto operator=([[maybe_unused]] T const& unnamed_param_2) -> v& ;
3332
public: v(v const&) = delete; /* No 'that' constructor, suppress copy */
3433
public: auto operator=(v const&) -> void = delete;
3534

36-
#line 33 "pure2-bugfix-for-deducible-parameters.cpp2"
35+
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
3736
};
3837

3938

4039
//=== Cpp2 function definitions =================================================
4140

4241
#line 1 "pure2-bugfix-for-deducible-parameters.cpp2"
4342

44-
#line 3 "pure2-bugfix-for-deducible-parameters.cpp2"
43+
#line 2 "pure2-bugfix-for-deducible-parameters.cpp2"
4544
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void{x.construct(); }
4645
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, [[maybe_unused]] T const& unnamed_param_2) -> void{x.construct(); }
4746
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&& { return x; }
@@ -55,33 +54,33 @@ auto main() -> int{
5554
cpp2::Default.expects(&id<zero>(z.value()) == &z.value(), "");
5655

5756
// Deducible parameters.
58-
static_cast<void>(v{0});
59-
static_cast<void>([]<typename T>(std::vector<T> const& x) mutable -> void{}(std::vector<cpp2::i32>{}));
60-
static_cast<void>([]<typename T>(std::vector<std::vector<T>> const& x) mutable -> void{}(std::vector<std::vector<cpp2::i32>>{}));
57+
static_cast<void>(v{ 0});
58+
[]<typename T>([[maybe_unused]] std::vector<T> const& unnamed_param_1) mutable -> void{}(std::vector<cpp2::i32>{});
59+
[]<typename T>([[maybe_unused]] std::vector<std::vector<T>> const& unnamed_param_1) mutable -> void{}(std::vector<std::vector<cpp2::i32>>{});
6160
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z); // Blocked on #727.
62-
static_cast<void>([]<typename T, typename U>(std::array<T,U::value> const& x, U const& y) mutable -> void{}(std::array<cpp2::i32,0>{}, z.value()));
61+
[]<typename T, typename U>([[maybe_unused]] std::array<T,U::value> const& unnamed_param_1, [[maybe_unused]] U const& unnamed_param_2) mutable -> void{}(std::array<cpp2::i32,0>{}, z.value());
6362
init(cpp2::out(&z.value()), z.value());
6463
id(z.value(), std::move(z.value()));
6564
{
66-
auto f = []<typename T>(std::vector<std::type_identity_t<T>> const& x) mutable -> void{};
65+
auto f = []<typename T>([[maybe_unused]] std::vector<std::type_identity_t<T>> const& unnamed_param_1) mutable -> void{};
6766

6867
// Test that these are emitted unwrapped in case they are deducible.
6968

70-
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
69+
#line 25 "pure2-bugfix-for-deducible-parameters.cpp2"
7170
static_assert(!(std::is_invocable_v<decltype(f),std::vector<cpp2::i32>>), "`T` is non-deducible.");
7271
}
7372
{
74-
auto f = []<typename T>(std::vector<std::vector<T>> const& x) mutable -> void{};
73+
auto f = []<typename T>([[maybe_unused]] std::vector<std::vector<T>> const& unnamed_param_1) mutable -> void{};
7574

76-
#line 28 "pure2-bugfix-for-deducible-parameters.cpp2"
75+
#line 27 "pure2-bugfix-for-deducible-parameters.cpp2"
7776
static_assert(std::is_invocable_v<decltype(std::move(f)),std::vector<std::vector<cpp2::i32>>>, "`T` is deducible.");
7877
}
79-
#line 29 "pure2-bugfix-for-deducible-parameters.cpp2"
78+
#line 28 "pure2-bugfix-for-deducible-parameters.cpp2"
8079
}
8180

82-
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
83-
template <typename T> v<T>::v(T const& x){}
84-
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
85-
template <typename T> auto v<T>::operator=(T const& x) -> v& {
81+
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
82+
template <typename T> v<T>::v([[maybe_unused]] T const& unnamed_param_2){}
83+
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
84+
template <typename T> auto v<T>::operator=([[maybe_unused]] T const& unnamed_param_2) -> v& {
8685
return *this; }
8786

regression-tests/test-results/pure2-bugfix-for-dependent-types.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ auto main() -> int{
102102
static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>(typename T::value_type{}); }); }); }); });
103103
static_cast<void>([]() mutable -> void{static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>(typename T::value_type{}); }); }); }); });
104104
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>(typename T::value_type{}); }); }); }); });
105-
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) mutable -> void{}); }); }); });
106-
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
107-
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
108-
static_cast<void>([]<typename T>(cpp2::in<typename T::value_type> x) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
105+
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{}); }); }); });
106+
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
107+
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
108+
static_cast<void>([]<typename T>([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
109109

110110
// Lookup.
111111
{

0 commit comments

Comments
 (0)