Skip to content

Commit 77b48c5

Browse files
committed
Add tests
1 parent 853a1e9 commit 77b48c5

13 files changed

+142
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
main: (args) = {
2+
p : *int;
3+
4+
a := 1;
5+
b := 2;
6+
c := 3;
7+
d := 4;
8+
9+
if args.argc == 3 {
10+
p = a&;
11+
} else if b > 2 {
12+
if args.argc == 2 {
13+
p = c&;
14+
} else {
15+
if b > 0 {
16+
p = a&;
17+
}
18+
else {
19+
p = d&;
20+
}
21+
}
22+
} else {
23+
// p = c&;
24+
}
25+
26+
std::cout << p* << std::endl;
27+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
main: (args) = {
2+
p : *int;
3+
4+
a := 1;
5+
b := 2;
6+
c := 3;
7+
d := 4;
8+
9+
if args.argc > 20 {
10+
c = 20;
11+
} else if args.argc > 10 {
12+
c = 10;
13+
} else {
14+
if args.argc % 2 {
15+
b = 2;
16+
} else {
17+
b = 1;
18+
}
19+
}
20+
21+
if args.argc == 3 {
22+
p = a&;
23+
} else if b > 2 {
24+
if args.argc == 2 {
25+
p = c&;
26+
} else {
27+
if b > 0 {
28+
p = a&;
29+
}
30+
else {
31+
p = d&;
32+
}
33+
}
34+
} else {
35+
p = c&;
36+
}
37+
38+
std::cout << p* << std::endl;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

regression-tests/test-results/apple-clang-14/pure2-nested-ifs.cpp.output

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

regression-tests/test-results/clang-12/pure2-nested-ifs.cpp.output

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

regression-tests/test-results/gcc-10/pure2-nested-ifs.cpp.output

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

regression-tests/test-results/msvc-2022/pure2-nested-ifs.cpp.output

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pure2-nested-ifs-error.cpp2...
2+
pure2-nested-ifs-error.cpp2(2,5): error: local variable p must be initialized on both branches or neither branch
3+
pure2-nested-ifs-error.cpp2(9,5): error: "if" initializes p on:
4+
branch starting at line 9
5+
branch starting at line 11
6+
but not on:
7+
branch starting at line 22
8+
==> program violates initialization safety guarantee - see previous errors
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
11+
//=== Cpp2 type definitions and function declarations ===========================
12+
13+
#line 1 "pure2-nested-ifs.cpp2"
14+
auto main(int const argc_, char const* const* const argv_) -> int;
15+
16+
17+
//=== Cpp2 function definitions =================================================
18+
19+
#line 1 "pure2-nested-ifs.cpp2"
20+
auto main(int const argc_, char const* const* const argv_) -> int{
21+
auto args = cpp2::make_args(argc_, argv_);
22+
#line 2 "pure2-nested-ifs.cpp2"
23+
cpp2::deferred_init<int*> p;
24+
25+
auto a {1};
26+
auto b {2};
27+
auto c {3};
28+
auto d {4};
29+
30+
if (cpp2::cmp_greater(args.argc,20)) {
31+
c = 20;
32+
} else if (cpp2::cmp_greater(args.argc,10)) {
33+
c = 10;
34+
}else {
35+
if (args.argc % 2) {
36+
b = 2;
37+
}else {
38+
b = 1;
39+
}
40+
}
41+
42+
if (args.argc==3) {
43+
p.construct(&a);
44+
} else if (cpp2::cmp_greater(b,2)) {
45+
if (args.argc==2) {
46+
p.construct(&c);
47+
}else {
48+
if (cpp2::cmp_greater(std::move(b),0)) {
49+
p.construct(&a);
50+
}
51+
else {
52+
p.construct(&d);
53+
}
54+
}
55+
}else {
56+
p.construct(&c);
57+
}
58+
59+
std::cout << *cpp2::assert_not_null(std::move(p.value())) << std::endl;
60+
}
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-nested-ifs.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)