Skip to content

Commit b0ff0aa

Browse files
committed
test: split off "deducible parameters" unit test
1 parent b8d0ba6 commit b0ff0aa

11 files changed

+110
-86
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Dependent, non-deducible parameters
2+
// are wrapped like non-dependent parameters.
3+
init: <T> (out x: std::integral_constant<i32, T::value>) = { x = (); }
4+
init: <T> (out x: std::integral_constant<i32, T::value>, _: T) = { x = (); }
5+
id: <T> (x: std::integral_constant<i32, T::value>) -> forward _ = x;
6+
id: <T> (x: std::integral_constant<i32, T::value>, y: T) = { [[assert: x& == y&]] }
7+
8+
main: () = {
9+
zero: type == std::integral_constant<i32, 0>;
10+
11+
z: zero;
12+
init<zero>(out z);
13+
[[assert: id<zero>(z)& == z&]]
14+
15+
// 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>> = ());
19+
// Uncomment once `typename` is supported for template arguments.
20+
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z);
21+
init(out z, z);
22+
id(z, z);
23+
}
24+
25+
v: <T> type = {
26+
operator=: (out this, x: T) = { }
27+
}
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,9 @@ t: @ struct <T: type> type = {
5151
x: T::value_type = 0;
5252
}
5353

54-
// Dependent, non-deducible parameters
55-
// are wrapped like non-dependent parameters.
56-
init: <T> (out x: std::integral_constant<i32, T::value>) = { x = (); }
57-
init: <T> (out x: std::integral_constant<i32, T::value>, _: T) = { x = (); }
58-
id: <T> (x: std::integral_constant<i32, T::value>) -> forward _ = x;
59-
id: <T> (x: std::integral_constant<i32, T::value>, y: T) = { [[assert: x& == y&]] }
60-
6154
main: () = {
6255
zero: type == std::integral_constant<i32, 0>;
63-
6456
_ = f<zero, 0>(0);
65-
_ = :t<zero>::u = ();
66-
67-
z: zero;
68-
init<zero>(out z);
69-
[[assert: id<zero>(z)& == z&]]
70-
71-
// Deducible parameters.
72-
_ = :v = 0;
73-
_ = :<T> (x: std::vector<T>) = {}(:std::vector<i32> = ());
74-
_ = :<T> (x: std::vector<std::vector<T>>) = {}(:std::vector<std::vector<i32>> = ());
75-
// Uncomment once `typename` is supported for template arguments.
76-
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z);
77-
init(out z, z);
78-
id(z, z);
7957

8058
// Nesting is irrelevant.
8159
_ = :<T> () = { _ = :T::value_type = (); };
@@ -104,7 +82,3 @@ main: () = {
10482
}
10583
}(0);
10684
}
107-
108-
v: <T> type = {
109-
operator=: (out this, x: T) = { }
110-
}

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

Whitespace-only changes.

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

Whitespace-only changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
#line 25 "pure2-bugfix-for-deducible-parameters.cpp2"
11+
template<typename T> class v;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
// Dependent, non-deducible parameters
17+
// are wrapped like non-dependent parameters.
18+
#line 3 "pure2-bugfix-for-deducible-parameters.cpp2"
19+
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void;
20+
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, T const& _) -> void;
21+
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&&;
22+
template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void;
23+
24+
auto main() -> int;
25+
26+
27+
#line 25 "pure2-bugfix-for-deducible-parameters.cpp2"
28+
template<typename T> class v {
29+
public: explicit v(T const& x);
30+
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
31+
public: auto operator=(T const& x) -> v& ;
32+
33+
public: v(v const&) = delete; /* No 'that' constructor, suppress copy */
34+
public: auto operator=(v const&) -> void = delete;
35+
#line 27 "pure2-bugfix-for-deducible-parameters.cpp2"
36+
};
37+
38+
39+
//=== Cpp2 function definitions =================================================
40+
41+
42+
#line 3 "pure2-bugfix-for-deducible-parameters.cpp2"
43+
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void{x.construct(); }
44+
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, T const& _) -> void{x.construct(); }
45+
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&& { return x; }
46+
template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void{cpp2::Default.expects(&x==&y, ""); }
47+
48+
auto main() -> int{
49+
using zero = std::integral_constant<cpp2::i32,0>;
50+
51+
cpp2::deferred_init<zero> z;
52+
init<zero>(cpp2::out(&z));
53+
cpp2::Default.expects(&id<zero>(z.value())==&z.value(), "");
54+
55+
// Deducible parameters.
56+
(void) v{0};
57+
(void) []<typename T>(std::vector<T> const& x) -> void{}(std::vector<cpp2::i32>{});
58+
(void) []<typename T>(std::vector<std::vector<T>> const& x) -> void{}(std::vector<std::vector<cpp2::i32>>{});
59+
// Uncomment once `typename` is supported for template arguments.
60+
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z);
61+
init(cpp2::out(&z.value()), z.value());
62+
id(z.value(), std::move(z.value()));
63+
}
64+
65+
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
66+
template <typename T> v<T>::v(T const& x){}
67+
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
68+
template <typename T> auto v<T>::operator=(T const& x) -> v& {
69+
return *this;
70+
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
71+
}
72+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-deducible-parameters.cpp2... ok (all Cpp2, passes safety checks)
2+

regression-tests/test-results/pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2.output

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,37 @@
77
#include "cpp2util.h"
88

99

10-
#line 46 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
10+
#line 46 "pure2-bugfix-for-dependent-types.cpp2"
1111
template<typename T> class t;
1212

1313

14-
#line 108 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
15-
template<typename T> class v;
16-
17-
1814
//=== Cpp2 type definitions and function declarations ===========================
1915

20-
#line 1 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
16+
#line 1 "pure2-bugfix-for-dependent-types.cpp2"
2117
template<typename T> using identity = T;
2218

2319
template<typename T, T::value_type V> [[nodiscard]] auto f(cpp2::in<typename T::value_type> x) -> T::value_type;
2420

2521

26-
#line 46 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
22+
#line 46 "pure2-bugfix-for-dependent-types.cpp2"
2723
template<typename T> class t {
2824
struct u_x_as_base { T::value_type x; };
2925

30-
#line 47 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
26+
#line 47 "pure2-bugfix-for-dependent-types.cpp2"
3127
public: class u: public u_x_as_base, public T::type {
3228

33-
#line 50 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
29+
#line 50 "pure2-bugfix-for-dependent-types.cpp2"
3430
};
3531
public: T::value_type x {0};
3632
};
3733

38-
// Dependent, non-deducible parameters
39-
// are wrapped like non-dependent parameters.
40-
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void;
41-
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, T const& _) -> void;
42-
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&&;
43-
template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void;
44-
4534
auto main() -> int;
4635

4736

48-
#line 108 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
49-
template<typename T> class v {
50-
public: explicit v(T const& x);
51-
#line 109 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
52-
public: auto operator=(T const& x) -> v& ;
53-
54-
public: v(v const&) = delete; /* No 'that' constructor, suppress copy */
55-
public: auto operator=(v const&) -> void = delete;
56-
#line 110 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
57-
};
58-
59-
6037
//=== Cpp2 function definitions =================================================
6138

6239

63-
#line 3 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
40+
#line 3 "pure2-bugfix-for-dependent-types.cpp2"
6441
template<typename T, T::value_type V> [[nodiscard]] auto f(cpp2::in<typename T::value_type> x) -> T::value_type{
6542
cpp2::Default.expects(cpp2::is<typename T::value_type>(x), "");
6643
cpp2::deferred_init<typename T::value_type> y;
@@ -104,30 +81,10 @@ template<typename T, T::value_type V> [[nodiscard]] auto f(cpp2::in<typename T::
10481
}
10582
}
10683

107-
#line 56 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
108-
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void{x.construct(); }
109-
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, T const& _) -> void{x.construct(); }
110-
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&& { return x; }
111-
template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void{cpp2::Default.expects(&x==&y, ""); }
112-
84+
#line 54 "pure2-bugfix-for-dependent-types.cpp2"
11385
auto main() -> int{
11486
using zero = std::integral_constant<cpp2::i32,0>;
115-
11687
(void) f<zero,0>(0);
117-
(void) t<zero>::u{};
118-
119-
cpp2::deferred_init<zero> z;
120-
init<zero>(cpp2::out(&z));
121-
cpp2::Default.expects(&id<zero>(z.value())==&z.value(), "");
122-
123-
// Deducible parameters.
124-
(void) v{0};
125-
(void) []<typename T>(std::vector<T> const& x) -> void{}(std::vector<cpp2::i32>{});
126-
(void) []<typename T>(std::vector<std::vector<T>> const& x) -> void{}(std::vector<std::vector<cpp2::i32>>{});
127-
// Uncomment once `typename` is supported for template arguments.
128-
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z);
129-
init(cpp2::out(&z.value()), z.value());
130-
id(z.value(), std::move(z.value()));
13188

13289
// Nesting is irrelevant.
13390
(void) []<typename T>() -> void{(void) typename T::value_type{}; };
@@ -157,11 +114,3 @@ auto main() -> int{
157114
}(0);
158115
}
159116

160-
#line 109 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
161-
template <typename T> v<T>::v(T const& x){}
162-
#line 109 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
163-
template <typename T> auto v<T>::operator=(T const& x) -> v& {
164-
return *this;
165-
#line 109 "pure2-bugfix-for-dependent-types-and-deducible-parameters.cpp2"
166-
}
167-
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-dependent-types.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)