Skip to content

Commit 7b5acc9

Browse files
committed
test: add unit tests for fixed UFCS corner cases
1 parent 82edeb6 commit 7b5acc9

25 files changed

+374
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
template<bool> struct t { };
2+
constexpr bool f(const t<true>&) { return true; }
3+
constexpr t<true> o{};
4+
5+
// Variables.
6+
7+
// _: <V: t<o.f()>> bool = (); // Blocked on #389, [GCC109781][].
8+
9+
// _: t<o.f()> = (); // Blocked on Clang 12 (lambda in unevaluated context).
10+
11+
_: bool = o.f();
12+
13+
// Functions.
14+
15+
// g: <V: t<o.f()>> () = { } // Blocked on [GCC109781][].
16+
17+
// g: (x: t<o.f()>) = { } // Blocked on Clang 12 (lambda in unevaluated context).
18+
19+
g: () [[pre: o.f()]] = { }
20+
21+
// h: () -> t<o.f()> = o; // Blocked on Clang 12 (lambda in unevaluated context).
22+
23+
// Aliases.
24+
25+
// a: <V: t<o.f()>> type == bool; // Blocked on [GCC109781][].
26+
27+
// b: <V: t<o.f()>> _ == false; // Blocked on [GCC109781][].
28+
29+
// c: type == t<o.f()>; // Blocked on Clang 12 (lambda in unevaluated context).
30+
31+
// d: _ == t<o.f()>(); // Blocked on Clang 12 (lambda in unevaluated context).
32+
33+
main: () = { }
34+
35+
// [GCC109781]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109781
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
print_res: (x: i32) -> i32 = {
2+
std::cout << x;
3+
if (x == 9) { std::cout << '\n'; }
4+
return x;
5+
}
6+
t: @struct type = {
7+
f: (inout this) -> i32 = print_res(0);
8+
f: (inout this, x) -> i32 = print_res(1);
9+
f: <T> (inout this) -> i32 = print_res(2);
10+
f: <T> (inout this, x) -> i32 = print_res(3);
11+
f: <T, U> (inout this, x, y) -> i32 = print_res(4);
12+
}
13+
f: (o: t) -> i32 = print_res(5);
14+
f: (o: t, x) -> i32 = print_res(6);
15+
f: <T> (o: t) -> i32 = print_res(7);
16+
f: <T> (o: t, x) -> i32 = print_res(8);
17+
f: <T, U> (o: t, x, y) -> i32 = print_res(9);
18+
m: t = ();
19+
n: const t = ();
20+
a: <T, U> _ == n;
21+
_: i32 = m.f();
22+
_: i32 = m.f(0);
23+
_: i32 = m.f<t>();
24+
_: i32 = m.f<t>(0);
25+
_: i32 = m.f<t, t>(0, 0);
26+
_: i32 = n.f();
27+
_: i32 = n.f(0);
28+
_: i32 = n.f<t>();
29+
_: i32 = n.f<t>(0);
30+
_: i32 = n.f<t, t>(0, 0);
31+
_: i32 = a<t, t>.f<t, t>(0, 0);
32+
main: () = {
33+
_: i32 = m.f();
34+
_: i32 = m.f(0);
35+
_: i32 = m.f<t>();
36+
_: i32 = m.f<t>(0);
37+
_: i32 = m.f<t, t>(0, 0);
38+
_: i32 = n.f();
39+
_: i32 = n.f(0);
40+
_: i32 = n.f<t>();
41+
_: i32 = n.f<t>(0);
42+
_: i32 = n.f<t, t>(0, 0);
43+
_: i32 = a<t, t>.f<t, t>(0, 0);
44+
45+
_ = :(a, f) = { _ = a.f(a).f(); };
46+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
t: type = {
2+
f: (this) -> i32 = 0;
3+
}
4+
main: () = {
5+
f := t().f();
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
t: type = {
2+
// swap: (inout this, that) = { } // Blocked on #508.
3+
}
4+
main: () = {
5+
// static_assert(noexcept(t().swap(t()))); // Blocked on Clang 12 (lambda in unevaluated context).
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// f: <T> () -> std::type_identity_t<decltype(T().a())> = { } // Blocked on Clang 12 (lambda in unevaluated context).
2+
B: type = { }
3+
main: () = {
4+
// static_assert(!std::invocable<decltype(:<T> (x: T) -> std::void_t<decltype(f<T>())> = {}), B>); // Blocked on Clang 12 (lambda in unevaluated context).
5+
}

regression-tests/test-results/clang-18/mixed-bugfix-for-ufcs-non-local.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/mixed-bugfix-for-ufcs-non-local.cpp.output

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0123456789
2+
9
3+
0123456789
4+
9

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-arguments.cpp.output

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-name-lookup.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-name-lookup.cpp.output

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-noexcept.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-noexcept.cpp.output

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-sfinae.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-ufcs-sfinae.cpp.output

Whitespace-only changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
3+
//=== Cpp2 type declarations ====================================================
4+
5+
6+
#include "cpp2util.h"
7+
8+
9+
10+
//=== Cpp2 type definitions and function declarations ===========================
11+
12+
template<bool> struct t { };
13+
constexpr bool f(const t<true>&) { return true; }
14+
constexpr t<true> o{};
15+
16+
// Variables.
17+
18+
// _: <V: t<o.f()>> bool = (); // Blocked on #389, [GCC109781][].
19+
20+
// _: t<o.f()> = (); // Blocked on Clang 12 (lambda in unevaluated context).
21+
22+
#line 11 "mixed-bugfix-for-ufcs-non-local.cpp2"
23+
extern bool auto_11_1;
24+
25+
// Functions.
26+
27+
// g: <V: t<o.f()>> () = { } // Blocked on [GCC109781][].
28+
29+
// g: (x: t<o.f()>) = { } // Blocked on Clang 12 (lambda in unevaluated context).
30+
31+
auto g() -> void;
32+
33+
// h: () -> t<o.f()> = o; // Blocked on Clang 12 (lambda in unevaluated context).
34+
35+
// Aliases.
36+
37+
// a: <V: t<o.f()>> type == bool; // Blocked on [GCC109781][].
38+
39+
// b: <V: t<o.f()>> _ == false; // Blocked on [GCC109781][].
40+
41+
// c: type == t<o.f()>; // Blocked on Clang 12 (lambda in unevaluated context).
42+
43+
// d: _ == t<o.f()>(); // Blocked on Clang 12 (lambda in unevaluated context).
44+
45+
auto main() -> int;
46+
47+
// [GCC109781]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109781
48+
49+
50+
//=== Cpp2 function definitions =================================================
51+
52+
53+
#line 11 "mixed-bugfix-for-ufcs-non-local.cpp2"
54+
bool auto_11_1 {CPP2_UFCS_NONLOCAL(f)(o)};
55+
56+
#line 19 "mixed-bugfix-for-ufcs-non-local.cpp2"
57+
auto g() -> void{
58+
cpp2::Default.expects(CPP2_UFCS(f)(o), "");
59+
#line 19 "mixed-bugfix-for-ufcs-non-local.cpp2"
60+
}
61+
62+
#line 33 "mixed-bugfix-for-ufcs-non-local.cpp2"
63+
auto main() -> int{}
64+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mixed-bugfix-for-ufcs-non-local.cpp2... ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)
2+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
#line 6 "pure2-bugfix-for-ufcs-arguments.cpp2"
11+
class t;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
[[nodiscard]] auto print_res(cpp2::in<cpp2::i32> x) -> cpp2::i32;
17+
18+
19+
#line 6 "pure2-bugfix-for-ufcs-arguments.cpp2"
20+
class t {
21+
public: [[nodiscard]] auto f() & -> cpp2::i32;
22+
public: [[nodiscard]] auto f(auto const& x) & -> cpp2::i32;
23+
public: template<typename T> [[nodiscard]] auto f() & -> cpp2::i32;
24+
public: template<typename T> [[nodiscard]] auto f(auto const& x) & -> cpp2::i32;
25+
public: template<typename T, typename U> [[nodiscard]] auto f(auto const& x, auto const& y) & -> cpp2::i32;
26+
};
27+
[[nodiscard]] auto f(cpp2::in<t> o) -> cpp2::i32;
28+
[[nodiscard]] auto f(cpp2::in<t> o, auto const& x) -> cpp2::i32;
29+
template<typename T> [[nodiscard]] auto f(cpp2::in<t> o) -> cpp2::i32;
30+
template<typename T> [[nodiscard]] auto f(cpp2::in<t> o, auto const& x) -> cpp2::i32;
31+
template<typename T, typename U> [[nodiscard]] auto f(cpp2::in<t> o, auto const& x, auto const& y) -> cpp2::i32;
32+
extern t m;
33+
extern t const n;
34+
template<typename T, typename U> auto static constexpr a = n;
35+
extern cpp2::i32 auto_21_1;
36+
extern cpp2::i32 auto_22_1;
37+
extern cpp2::i32 auto_23_1;
38+
extern cpp2::i32 auto_24_1;
39+
extern cpp2::i32 auto_25_1;
40+
extern cpp2::i32 auto_26_1;
41+
extern cpp2::i32 auto_27_1;
42+
extern cpp2::i32 auto_28_1;
43+
extern cpp2::i32 auto_29_1;
44+
extern cpp2::i32 auto_30_1;
45+
extern cpp2::i32 auto_31_1;
46+
auto main() -> int;
47+
48+
49+
//=== Cpp2 function definitions =================================================
50+
51+
[[nodiscard]] auto print_res(cpp2::in<cpp2::i32> x) -> cpp2::i32{
52+
std::cout << x;
53+
if ((x == 9)) {std::cout << '\n'; }
54+
return x;
55+
}
56+
57+
[[nodiscard]] auto t::f() & -> cpp2::i32 { return print_res(0); }
58+
[[nodiscard]] auto t::f(auto const& x) & -> cpp2::i32 { return print_res(1); }
59+
template<typename T> [[nodiscard]] auto t::f() & -> cpp2::i32 { return print_res(2); }
60+
template<typename T> [[nodiscard]] auto t::f(auto const& x) & -> cpp2::i32 { return print_res(3); }
61+
template<typename T, typename U> [[nodiscard]] auto t::f(auto const& x, auto const& y) & -> cpp2::i32 { return print_res(4); }
62+
63+
[[nodiscard]] auto f(cpp2::in<t> o) -> cpp2::i32 { return print_res(5); }
64+
[[nodiscard]] auto f(cpp2::in<t> o, auto const& x) -> cpp2::i32 { return print_res(6); }
65+
template<typename T> [[nodiscard]] auto f(cpp2::in<t> o) -> cpp2::i32 { return print_res(7); }
66+
template<typename T> [[nodiscard]] auto f(cpp2::in<t> o, auto const& x) -> cpp2::i32 { return print_res(8); }
67+
template<typename T, typename U> [[nodiscard]] auto f(cpp2::in<t> o, auto const& x, auto const& y) -> cpp2::i32 { return print_res(9); }
68+
t m {};
69+
t const n {};
70+
71+
cpp2::i32 auto_21_1 {CPP2_UFCS_NONLOCAL(f)(m)};
72+
cpp2::i32 auto_22_1 {CPP2_UFCS_NONLOCAL(f)(m, 0)};
73+
cpp2::i32 auto_23_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t>)(m)};
74+
cpp2::i32 auto_24_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t>)(m, 0)};
75+
cpp2::i32 auto_25_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t,t>)(m, 0, 0)};
76+
cpp2::i32 auto_26_1 {CPP2_UFCS_NONLOCAL(f)(n)};
77+
cpp2::i32 auto_27_1 {CPP2_UFCS_NONLOCAL(f)(n, 0)};
78+
cpp2::i32 auto_28_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t>)(n)};
79+
cpp2::i32 auto_29_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t>)(n, 0)};
80+
cpp2::i32 auto_30_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t,t>)(n, 0, 0)};
81+
cpp2::i32 auto_31_1 {CPP2_UFCS_TEMPLATE_NONLOCAL(f<t,t>)(a<t,t>, 0, 0)};
82+
auto main() -> int{
83+
cpp2::i32 auto_33_3 {CPP2_UFCS(f)(m)};
84+
cpp2::i32 auto_34_3 {CPP2_UFCS(f)(m, 0)};
85+
cpp2::i32 auto_35_3 {CPP2_UFCS_TEMPLATE(f<t>)(m)};
86+
cpp2::i32 auto_36_3 {CPP2_UFCS_TEMPLATE(f<t>)(m, 0)};
87+
cpp2::i32 auto_37_3 {CPP2_UFCS_TEMPLATE(f<t,t>)(m, 0, 0)};
88+
cpp2::i32 auto_38_3 {CPP2_UFCS(f)(n)};
89+
cpp2::i32 auto_39_3 {CPP2_UFCS(f)(n, 0)};
90+
cpp2::i32 auto_40_3 {CPP2_UFCS_TEMPLATE(f<t>)(n)};
91+
cpp2::i32 auto_41_3 {CPP2_UFCS_TEMPLATE(f<t>)(n, 0)};
92+
cpp2::i32 auto_42_3 {CPP2_UFCS_TEMPLATE(f<t,t>)(n, 0, 0)};
93+
cpp2::i32 auto_43_3 {CPP2_UFCS_TEMPLATE(f<t,t>)(a<t,t>, 0, 0)};
94+
95+
static_cast<void>([](auto const& a, auto const& f) -> void{static_cast<void>(CPP2_UFCS(f)(CPP2_UFCS(f)(a, a))); });
96+
}
97+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-ufcs-arguments.cpp2... ok (all Cpp2, passes safety checks)
2+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
class t;
10+
11+
12+
//=== Cpp2 type definitions and function declarations ===========================
13+
14+
class t {
15+
public: [[nodiscard]] auto f() const& -> cpp2::i32;
16+
17+
public: t() = default;
18+
public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
19+
public: auto operator=(t const&) -> void = delete;
20+
#line 3 "pure2-bugfix-for-ufcs-name-lookup.cpp2"
21+
};
22+
auto main() -> int;
23+
24+
25+
//=== Cpp2 function definitions =================================================
26+
27+
28+
#line 2 "pure2-bugfix-for-ufcs-name-lookup.cpp2"
29+
[[nodiscard]] auto t::f() const& -> cpp2::i32 { return 0; }
30+
31+
auto main() -> int{
32+
auto f {t().f()};
33+
}
34+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-ufcs-name-lookup.cpp2... ok (all Cpp2, passes safety checks)
2+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
class t;
10+
11+
12+
//=== Cpp2 type definitions and function declarations ===========================
13+
14+
class t {
15+
public: t() = default;
16+
public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
17+
public: auto operator=(t const&) -> void = delete;
18+
19+
// swap: (inout this, that) = { } // Blocked on #508.
20+
#line 3 "pure2-bugfix-for-ufcs-noexcept.cpp2"
21+
};
22+
auto main() -> int;
23+
24+
25+
//=== Cpp2 function definitions =================================================
26+
27+
28+
#line 4 "pure2-bugfix-for-ufcs-noexcept.cpp2"
29+
auto main() -> int{
30+
// static_assert(noexcept(t().swap(t()))); // Blocked on Clang 12 (lambda in unevaluated context).
31+
}
32+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-ufcs-noexcept.cpp2... ok (all Cpp2, passes safety checks)
2+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
#line 2 "pure2-bugfix-for-ufcs-sfinae.cpp2"
11+
class B;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
// f: <T> () -> std::type_identity_t<decltype(T().a())> = { } // Blocked on Clang 12 (lambda in unevaluated context).
17+
#line 2 "pure2-bugfix-for-ufcs-sfinae.cpp2"
18+
class B {
19+
public: B() = default;
20+
public: B(B const&) = delete; /* No 'that' constructor, suppress copy */
21+
public: auto operator=(B const&) -> void = delete;
22+
23+
#line 2 "pure2-bugfix-for-ufcs-sfinae.cpp2"
24+
};
25+
auto main() -> int;
26+
27+
28+
//=== Cpp2 function definitions =================================================
29+
30+
31+
#line 3 "pure2-bugfix-for-ufcs-sfinae.cpp2"
32+
auto main() -> int {
33+
// static_assert(!std::invocable<decltype(:<T> (x: T) -> std::void_t<decltype(f<T>())> = {}), B>); // Blocked on Clang 12 (lambda in unevaluated context).
34+
}
35+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-ufcs-sfinae.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)