diff --git a/regression-tests/pure2-nested-ifs-error.cpp2 b/regression-tests/pure2-nested-ifs-error.cpp2 new file mode 100644 index 0000000000..8ff11f1f08 --- /dev/null +++ b/regression-tests/pure2-nested-ifs-error.cpp2 @@ -0,0 +1,27 @@ +main: (args) = { + p : *int; + + a := 1; + b := 2; + c := 3; + d := 4; + + if args.argc == 3 { + p = a&; + } else if b > 2 { + if args.argc == 2 { + p = c&; + } else { + if b > 0 { + p = a&; + } + else { + p = d&; + } + } + } else { + // p = c&; + } + + std::cout << p* << std::endl; +} \ No newline at end of file diff --git a/regression-tests/pure2-nested-ifs.cpp2 b/regression-tests/pure2-nested-ifs.cpp2 new file mode 100644 index 0000000000..5f53242e6f --- /dev/null +++ b/regression-tests/pure2-nested-ifs.cpp2 @@ -0,0 +1,39 @@ +main: (args) = { + p : *int; + + a := 1; + b := 2; + c := 3; + d := 4; + + if args.argc > 20 { + c = 20; + } else if args.argc > 10 { + c = 10; + } else { + if args.argc % 2 { + b = 2; + } else { + b = 1; + } + } + + if args.argc == 3 { + p = a&; + } else if b > 2 { + if args.argc == 2 { + p = c&; + } else { + if b > 0 { + p = a&; + } + else { + p = d&; + } + } + } else { + p = c&; + } + + std::cout << p* << std::endl; +} \ No newline at end of file diff --git a/regression-tests/test-results/apple-clang-14/pure2-nested-ifs.cpp.execution b/regression-tests/test-results/apple-clang-14/pure2-nested-ifs.cpp.execution new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/regression-tests/test-results/apple-clang-14/pure2-nested-ifs.cpp.execution @@ -0,0 +1 @@ +3 diff --git a/regression-tests/test-results/apple-clang-14/pure2-nested-ifs.cpp.output b/regression-tests/test-results/apple-clang-14/pure2-nested-ifs.cpp.output new file mode 100644 index 0000000000..e69de29bb2 diff --git a/regression-tests/test-results/clang-12/pure2-nested-ifs.cpp.execution b/regression-tests/test-results/clang-12/pure2-nested-ifs.cpp.execution new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/regression-tests/test-results/clang-12/pure2-nested-ifs.cpp.execution @@ -0,0 +1 @@ +3 diff --git a/regression-tests/test-results/clang-12/pure2-nested-ifs.cpp.output b/regression-tests/test-results/clang-12/pure2-nested-ifs.cpp.output new file mode 100644 index 0000000000..e69de29bb2 diff --git a/regression-tests/test-results/gcc-10/pure2-nested-ifs.cpp.execution b/regression-tests/test-results/gcc-10/pure2-nested-ifs.cpp.execution new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/regression-tests/test-results/gcc-10/pure2-nested-ifs.cpp.execution @@ -0,0 +1 @@ +3 diff --git a/regression-tests/test-results/gcc-10/pure2-nested-ifs.cpp.output b/regression-tests/test-results/gcc-10/pure2-nested-ifs.cpp.output new file mode 100644 index 0000000000..e69de29bb2 diff --git a/regression-tests/test-results/msvc-2022/pure2-nested-ifs.cpp.execution b/regression-tests/test-results/msvc-2022/pure2-nested-ifs.cpp.execution new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/regression-tests/test-results/msvc-2022/pure2-nested-ifs.cpp.execution @@ -0,0 +1 @@ +3 diff --git a/regression-tests/test-results/msvc-2022/pure2-nested-ifs.cpp.output b/regression-tests/test-results/msvc-2022/pure2-nested-ifs.cpp.output new file mode 100644 index 0000000000..e69de29bb2 diff --git a/regression-tests/test-results/pure2-nested-ifs-error.cpp2.output b/regression-tests/test-results/pure2-nested-ifs-error.cpp2.output new file mode 100644 index 0000000000..9e33ea748d --- /dev/null +++ b/regression-tests/test-results/pure2-nested-ifs-error.cpp2.output @@ -0,0 +1,9 @@ +pure2-nested-ifs-error.cpp2... +pure2-nested-ifs-error.cpp2(2,5): error: local variable p must be initialized on both branches or neither branch +pure2-nested-ifs-error.cpp2(9,5): error: "if" initializes p on: + branch starting at line 9 + branch starting at line 11 +but not on: + branch starting at line 22 + ==> program violates initialization safety guarantee - see previous errors + diff --git a/regression-tests/test-results/pure2-nested-ifs.cpp b/regression-tests/test-results/pure2-nested-ifs.cpp new file mode 100644 index 0000000000..4bacd63363 --- /dev/null +++ b/regression-tests/test-results/pure2-nested-ifs.cpp @@ -0,0 +1,61 @@ + +#define CPP2_USE_MODULES Yes + +//=== Cpp2 type declarations ==================================================== + + +#include "cpp2util.h" + + + +//=== Cpp2 type definitions and function declarations =========================== + +#line 1 "pure2-nested-ifs.cpp2" +auto main(int const argc_, char const* const* const argv_) -> int; + + +//=== Cpp2 function definitions ================================================= + +#line 1 "pure2-nested-ifs.cpp2" +auto main(int const argc_, char const* const* const argv_) -> int{ + auto args = cpp2::make_args(argc_, argv_); +#line 2 "pure2-nested-ifs.cpp2" + cpp2::deferred_init p; + + auto a {1}; + auto b {2}; + auto c {3}; + auto d {4}; + + if (cpp2::cmp_greater(args.argc,20)) { + c = 20; + } else if (cpp2::cmp_greater(args.argc,10)) { + c = 10; + }else { + if (args.argc % 2) { + b = 2; + }else { + b = 1; + } + } + + if (args.argc==3) { + p.construct(&a); + } else if (cpp2::cmp_greater(b,2)) { + if (args.argc==2) { + p.construct(&c); + }else { + if (cpp2::cmp_greater(std::move(b),0)) { + p.construct(&a); + } + else { + p.construct(&d); + } + } + }else { + p.construct(&c); + } + + std::cout << *cpp2::assert_not_null(std::move(p.value())) << std::endl; +} + diff --git a/regression-tests/test-results/pure2-nested-ifs.cpp2.output b/regression-tests/test-results/pure2-nested-ifs.cpp2.output new file mode 100644 index 0000000000..2ac9b570c8 --- /dev/null +++ b/regression-tests/test-results/pure2-nested-ifs.cpp2.output @@ -0,0 +1,2 @@ +pure2-nested-ifs.cpp2... ok (all Cpp2, passes safety checks) +