diff --git a/include/cpp2util.h b/include/cpp2util.h index cffd93ac9..7d7e5177b 100644 --- a/include/cpp2util.h +++ b/include/cpp2util.h @@ -711,8 +711,28 @@ struct { } inline shared; template -[[nodiscard]] auto cpp2_new(auto&& ...args) -> std::unique_ptr { - return unique.cpp2_new(CPP2_FORWARD(args)...); +class owning_reference { +public: + explicit owning_reference(std::unique_ptr&& ptr):_ptr(cpp2::impl::assert_not_null(std::move(ptr))){} + ~owning_reference() = default; + owning_reference(const owning_reference& ref) = delete; + owning_reference& operator=(const owning_reference& ref) noexcept = delete; + owning_reference(owning_reference&& ref) = default; + owning_reference& operator=(owning_reference&& ref) noexcept = default; + typename std::add_lvalue_reference::type operator*() const { return *cpp2::impl::assert_not_null(_ptr.get()); } + typename std::add_lvalue_reference::type operator->() const noexcept {return *cpp2::impl::assert_not_null(_ptr.get());} + auto get() const noexcept { return _ptr.get();} +private: + std::unique_ptr _ptr; +}; + +template +[[nodiscard]] auto cpp2_new(auto&& ...args) -> std::optional> { + auto _ptr = unique.cpp2_new(CPP2_FORWARD(args)...); + if (_ptr) { + return owning_reference{std::move(_ptr)}; + } + return {}; } diff --git a/regression-tests/clang++-15.patch b/regression-tests/clang++-15.patch new file mode 100644 index 000000000..3bfa201b6 --- /dev/null +++ b/regression-tests/clang++-15.patch @@ -0,0 +1,2505 @@ + +diff --git a/regression-tests/test-results/mixed-type-safety-1.cpp b/regression-tests/test-results/mixed-type-safety-1.cpp +index f175980..20aecdc 100644 +--- a/regression-tests/test-results/mixed-type-safety-1.cpp ++++ b/regression-tests/test-results/mixed-type-safety-1.cpp +@@ -58,7 +58,7 @@ auto print(cpp2::impl::in msg, cpp2::impl::in b) -> void + print( "1 is int? ", cpp2::impl::is(1)); + + auto c {cpp2_new()}; // safe by construction +- Shape* s {CPP2_UFCS(get)(cpp2::move(c))}; // safe by Lifetime ++ Shape* s {CPP2_UFCS(get)((*cpp2::impl::assert_not_null(cpp2::move(c))))}; // safe by Lifetime + print(" +s* is Shape? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); + print( "s* is Circle? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); + print( "s* is Square? ", cpp2::impl::is(*cpp2::impl::assert_not_null(cpp2::move(s)))); + + +diff --git a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +index 17021ed..cfefcc2 100644 +--- a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +@@ -5,7 +5,7 @@ pure2-assert-expected-not-null.cpp2:7:10: error: no member named 'expected' in n + std::expected ex {4}; + ~~~~~^~~~~~~~ + unexpected +-/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here + void unexpected() __attribute__ ((__noreturn__)); + ^ + pure2-assert-expected-not-null.cpp2:9:193: error: use of undeclared identifier 'ex' +@@ -18,7 +18,7 @@ pure2-assert-expected-not-null.cpp2:14:10: error: no member named 'expected' in + std::expected ex {std::unexpected(false)}; + ~~~~~^~~~~~~~ + unexpected +-/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here + void unexpected() __attribute__ ((__noreturn__)); + ^ + pure2-assert-expected-not-null.cpp2:15:52: error: use of undeclared identifier 'ex' + + +diff --git a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +index 850cfc6..7dbfcb5 100644 +--- a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution ++++ b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +@@ -9,4 +9,4 @@ g0g0g + pl(ug$h + 0pl(ug$h + Dog kennel color mauve price 3.14 in stock = true +-Dog kennel color mauve price 3.14 in stock = true ++Dog kennel color mauve price 3.140000 in stock = true + + +diff --git a/regression-tests/test-results/pure2-intro-example-three-loops.cpp b/regression-tests/test-results/pure2-intro-example-three-loops.cpp +index 500f293..ea0af88 100644 +--- a/regression-tests/test-results/pure2-intro-example-three-loops.cpp ++++ b/regression-tests/test-results/pure2-intro-example-three-loops.cpp +@@ -45,7 +45,12 @@ auto decorate_and_print(auto& thing) -> void{ + "hello", "big", "world"}; + std::span view {words}; + +- auto i {cpp2_new(0)}; ++ auto p_i {cpp2_new(0)}; ++ if ((!(p_i))) { ++ return 1; ++ } ++ auto i {*cpp2::impl::assert_not_null(cpp2::move(p_i))}; ++ + for( ; cpp2::impl::cmp_less(*cpp2::impl::assert_not_null(i),CPP2_UFCS(ssize)(view)); ++*cpp2::impl::assert_not_null(i) ) { + print(CPP2_ASSERT_IN_BOUNDS(view, *cpp2::impl::assert_not_null(i))); + } + + +diff --git a/regression-tests/test-results/clang-15/pure2-intro-example-three-loops.cpp.output b/regression-tests/test-results/clang-15/pure2-intro-example-three-loops.cpp.output +index e69de29..b3b3fdb 100644 +--- a/regression-tests/test-results/clang-15/pure2-intro-example-three-loops.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-intro-example-three-loops.cpp.output +@@ -0,0 +1,7 @@ ++pure2-intro-example-three-loops.cpp2:19:10: error: call to implicitly-deleted copy constructor of 'cpp2::owning_reference' ++ auto i {*cpp2::impl::assert_not_null(cpp2::move(p_i))}; ++ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ++../../../include/cpp2util.h:718:5: note: copy constructor is implicitly deleted because 'owning_reference' has a user-declared move constructor ++ owning_reference(owning_reference&& ref) = default; ++ ^ ++1 error generated. + + +diff --git a/regression-tests/test-results/pure2-last-use.cpp b/regression-tests/test-results/pure2-last-use.cpp +index 8d72435..ec663a6 100644 +--- a/regression-tests/test-results/pure2-last-use.cpp ++++ b/regression-tests/test-results/pure2-last-use.cpp +@@ -362,9 +362,9 @@ class issue_857_9: public issue_857_8 { + }; + + class issue_869_0 { +- public: explicit issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2); ++ public: explicit issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2); + #line 373 "pure2-last-use.cpp2" +- public: auto operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& ; ++ public: auto operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& ; + public: [[nodiscard]] auto operator<=>([[maybe_unused]] issue_869_0 const& that) const& -> std::strong_ordering = default; + public: issue_869_0([[maybe_unused]] issue_869_0 const& that); + +@@ -520,57 +520,57 @@ requires (!(std::copyable)) { return std::move(cpp2::move(x)); } + #line 9 "pure2-last-use.cpp2" + auto issue_313() -> void{ + // _ = :() -> std::vector = { +-// a := new(0); ++// a := new(0)*; + // return (a*, identity_copy(a)*); + // }; + // _ = :() -> std::vector = { +-// a := new(0); ++// a := new(0)*; + // return (a&**, identity_copy(a)*); + // }; + static_cast([]() mutable -> int{ +- auto a {cpp2_new(0)}; ++ auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(a)) + *cpp2::impl::assert_not_null(identity(a)); + +- auto b {cpp2_new(0)}; ++ auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b)); + +- auto c {cpp2_new(0)}; ++ auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(c)) ^ *cpp2::impl::assert_not_null(identity(c)); + }); + { +- auto a {cpp2_new(0)}; ++ auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; + *cpp2::impl::assert_not_null(identity(a)) = *cpp2::impl::assert_not_null(identity(a)); + +- auto b {cpp2_new(0)}; ++ auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; + int auto_1 {*cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b))}; + +- auto c {cpp2_new(0)}; ++ auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (*cpp2::impl::assert_not_null(identity(c)) * *cpp2::impl::assert_not_null(identity(c))) {} + +- auto d {cpp2_new(0)}; ++ auto d {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if ((*cpp2::impl::assert_not_null(identity(d)) - *cpp2::impl::assert_not_null(identity(d)))) {} + +- auto e {cpp2_new(0)}; ++ auto e {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast(cpp2::impl::is(e, (e))); + +- auto f {cpp2_new(0)}; ++ auto f {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast(cpp2::impl::is>(f));// OK? + +- auto g {cpp2_new(0)}; ++ auto g {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { *cpp2::impl::assert_not_null(identity(g)) + *cpp2::impl::assert_not_null(identity(g)) } ) + {} + +- auto h {cpp2_new(0)}; ++ auto h {*cpp2::impl::assert_not_null(cpp2_new(0))}; + while( *cpp2::impl::assert_not_null(identity(h)) + *cpp2::impl::assert_not_null(identity(h)) ) + {} + +- auto i {cpp2_new(0)}; ++ auto i {*cpp2::impl::assert_not_null(cpp2_new(0))}; + do {} while ( + *cpp2::impl::assert_not_null(identity(i)) + *cpp2::impl::assert_not_null(identity(i))); + +- auto j {cpp2_new(0)}; +- auto k {cpp2_new(0)}; ++ auto j {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ auto k {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast([&] () -> int { auto&& _expr = *cpp2::impl::assert_not_null(identity(j)) + *cpp2::impl::assert_not_null(identity(j)); + if (cpp2::impl::is(_expr, (*cpp2::impl::assert_not_null(identity(k)) + *cpp2::impl::assert_not_null(identity(k))))) { if constexpr( requires{0;} ) if constexpr( std::is_convertible_v ) return 0; else return int{}; else return int{}; } + else return 0; } +@@ -578,7 +578,7 @@ auto issue_313() -> void{ + + } + // { +-// a := new(0); ++// a := new(0)*; + // _ = :() identity(a$)* + identity(a$)*; + // } + } +@@ -613,7 +613,7 @@ auto issue_683(auto const& args) -> void{ + auto issue_825() -> void{ + static_cast([](std::unique_ptr b) mutable -> auto { return f_copy(std::move(cpp2::move(b))); }); + static_cast([](std::unique_ptr&& c) mutable -> auto { return f_copy(std::move(cpp2::move(c))); }); +- static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(cpp2_new(0))); ++ static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(*cpp2::impl::assert_not_null(cpp2_new(0)))); + } + + #line 120 "pure2-last-use.cpp2" +@@ -730,10 +730,10 @@ int gi {0}; + auto issue_857_9::g2() && -> void { f_inout(cpp2::move((*this)).c); } + + #line 373 "pure2-last-use.cpp2" +- issue_869_0::issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2){} ++ issue_869_0::issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2){} + #line 373 "pure2-last-use.cpp2" +- auto issue_869_0::operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& { +- return *this; } ++ auto issue_869_0::operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& { ++ return *this; } + + + issue_869_0::issue_869_0([[maybe_unused]] issue_869_0 const& that){} +@@ -781,13 +781,13 @@ issue_869_1::issue_869_1(issue_869_1 const& that) + } + #line 378 "pure2-last-use.cpp2" + [[nodiscard]] auto issue_869_2() -> issue_869_2_ret{ +- issue_869_1 res {}; CPP2_UFCS(set_i)(res, cpp2_new(0)); ++ issue_869_1 res {}; CPP2_UFCS(set_i)(res, *cpp2::impl::assert_not_null(cpp2_new(0))); + #line 379 "pure2-last-use.cpp2" + return res; } + #line 380 "pure2-last-use.cpp2" + auto issue_884() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + { + {f_inout(x); } +@@ -796,7 +796,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -807,7 +807,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -819,7 +819,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + if (true) { + static_cast(0); +@@ -832,7 +832,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -845,7 +845,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -858,7 +858,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -871,7 +871,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -884,7 +884,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -897,7 +897,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -910,7 +910,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_inout(x); +@@ -926,7 +926,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_inout(x); +@@ -942,7 +942,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -958,7 +958,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + if (true) { +@@ -971,7 +971,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + if (true) { +@@ -985,7 +985,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + } + else { +@@ -998,7 +998,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -1012,9 +1012,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + f_copy(std::move(cpp2::move(y))); + } +@@ -1029,9 +1029,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + else { + f_copy(std::move(cpp2::move(x))); +@@ -1041,7 +1041,7 @@ auto issue_884() -> void{ + else { + if (true) { + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(y))); + f_inout(x); + } +@@ -1051,9 +1051,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + else { + f_copy(std::move(cpp2::move(x))); +@@ -1061,7 +1061,7 @@ auto issue_884() -> void{ + } + } + else { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -1075,13 +1075,13 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } + else { + if (true) { +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -1094,10 +1094,10 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -1113,7 +1113,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + + if (true) { + f_inout(x); +@@ -1127,7 +1127,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + f_inout(x); +@@ -1193,9 +1193,9 @@ auto issue_888_1([[maybe_unused]] std::string unnamed_param_1, move_only_functio + + #line 784 "pure2-last-use.cpp2" + auto issue_890() -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + { +-auto const& x{cpp2_new(0)}; ++auto const& x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + // assert(identity_copy(x)* == 0); + #line 787 "pure2-last-use.cpp2" + if (cpp2::cpp2_default.is_active() && !(*cpp2::impl::assert_not_null(identity(x)) == 0) ) { cpp2::cpp2_default.report_violation(""); } +@@ -1224,13 +1224,13 @@ auto enum_0() -> void{ + } + #line 806 "pure2-last-use.cpp2" + auto enum_1() -> void{ +- auto max_value {cpp2_new(0)}; +- std::reference_wrapper const> min_value {cpp2::move(max_value)}; ++ auto max_value {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ std::reference_wrapper const> min_value {cpp2::move(max_value)}; + + // for (0) + // do (copy x) + // { +- // v := new(identity_copy(x)); ++ // v := new(identity_copy(x))*; + // if pred(v, min_value) { + // min_value = std::ref(identity(v)); // Not using 'else' will never move 'v'. + // } +@@ -1239,21 +1239,21 @@ auto enum_1() -> void{ + // } + // } + +- auto y {cpp2_new(false)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(false))}; + while( *cpp2::impl::assert_not_null(identity(y)) ) { +- auto v {cpp2_new(0)}; ++ auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(v))); + } + +- auto z {cpp2_new(false)}; ++ auto z {*cpp2::impl::assert_not_null(cpp2_new(false))}; + do { +- auto v {cpp2_new(0)}; ++ auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(v))); + } while ( *cpp2::impl::assert_not_null(identity(z))); + } + #line 834 "pure2-last-use.cpp2" + auto enum_2() -> void{ +- auto umax {cpp2_new(0)}; ++ auto umax {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (pred(umax)) { + } + else {if (pred(umax)) { +@@ -1299,14 +1299,14 @@ return std::move(p.value()); } + #line 875 "pure2-last-use.cpp2" + auto loops() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) + f_inout(x); + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) { do +@@ -1314,14 +1314,14 @@ auto loops() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) + if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(get)(x)) ) { cpp2::cpp2_default.report_violation(""); } + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -1337,10 +1337,10 @@ namespace captures { + + #line 915 "pure2-last-use.cpp2" + auto f() -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + auto id {[](auto const& x) mutable -> auto&& { return x; }}; +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (cpp2::cpp2_default.is_active() && !(&cpp2::move(id)(y) == &y) ) { cpp2::cpp2_default.report_violation(""); } + } + +@@ -1360,13 +1360,13 @@ auto f() -> void{ + #line 940 "pure2-last-use.cpp2" + auto g() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + static_cast([_0 = std::array auto { return identity(x); }(0)>()]() mutable -> auto { return _0; });// Fails on Clang 12 (lambda in unevaluated context). + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(cpp2::move(x)); + // _ = :() -> int = (:() x$*)$(); + }); +@@ -1377,7 +1377,7 @@ auto g() -> void{ + #line 956 "pure2-last-use.cpp2" + auto loops_and_captures() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { [](auto const& x) mutable -> auto { return x; } } ) +@@ -1385,7 +1385,7 @@ auto loops_and_captures() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + for ( + +@@ -1395,7 +1395,7 @@ auto loops_and_captures() -> void{ + }); + + // _ = :() = { +-// x := new(0); ++// x := new(0)*; + // for (:() x$*) + // do (_) + // { } +@@ -1405,10 +1405,10 @@ auto loops_and_captures() -> void{ + #line 994 "pure2-last-use.cpp2" + auto skip_hidden_names() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + { +-auto x{cpp2_new(0)}; ++auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + + #line 999 "pure2-last-use.cpp2" + f_copy(std::move(cpp2::move(x))); +@@ -1417,10 +1417,10 @@ auto x{cpp2_new(0)}; + }); + + // _ = :() = { +-// x := new(0); ++// x := new(0)*; + // _ = :() = { + // _ = x$; +-// x := new(1); ++// x := new(1)*; + // _ = :() = { + // _ = x$; + // }; +@@ -1429,8 +1429,8 @@ auto x{cpp2_new(0)}; + + static_cast([]() mutable -> void{ + { +-auto x{cpp2_new(0)}; +- // x := new(0); ++auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ // x := new(0)*; + // f_copy(x); + // for (0) + // do (copy x) +@@ -1443,7 +1443,7 @@ auto x{cpp2_new(0)}; + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + { + f_copy(std::move(cpp2::move(x))); +@@ -1453,10 +1453,10 @@ auto x{cpp2_new(0)}; + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + static_cast([]() mutable -> void{ +- static_assert(std::is_same_v>); ++ static_assert(std::is_same_v>); + using captures::x; + f_inout(x); + }); + + +diff --git a/regression-tests/test-results/pure2-new-basics.cpp2.output b/regression-tests/test-results/pure2-new-basics.cpp2.output +index 1be2648..cb7037c 100644 +--- a/regression-tests/test-results/pure2-new-basics.cpp2.output ++++ b/regression-tests/test-results/pure2-new-basics.cpp2.output +@@ -1,2 +1,3 @@ +-pure2-new-basics.cpp2... ok (all Cpp2, passes safety checks) ++pure2-new-basics.cpp2... ++pure2-new-basics.cpp2(40,9): error: invalid statement encountered inside a compound-statement (at 'move_test') + + + +diff --git a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output +index e69de29..4b68b87 100644 +--- a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output +@@ -0,0 +1,135 @@ ++pure2-new-basics.cpp2:33:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:33:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:34:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:34:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:36:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto c {*cpp2::assert_not_null(std::move(a))}; ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:37:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(c)); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:38:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(std::move(c)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:46:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:46:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:51:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:51:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:71:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:71:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:72:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:72:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:73:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:73:41: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:76:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:76:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++fatal error: too many errors emitted, stopping now [-ferror-limit=] ++20 errors generated. + + +diff --git a/regression-tests/test-results/mixed-type-safety-1.cpp b/regression-tests/test-results/mixed-type-safety-1.cpp +index f175980..20aecdc 100644 +--- a/regression-tests/test-results/mixed-type-safety-1.cpp ++++ b/regression-tests/test-results/mixed-type-safety-1.cpp +@@ -58,7 +58,7 @@ auto print(cpp2::impl::in msg, cpp2::impl::in b) -> void + print( "1 is int? ", cpp2::impl::is(1)); + + auto c {cpp2_new()}; // safe by construction +- Shape* s {CPP2_UFCS(get)(cpp2::move(c))}; // safe by Lifetime ++ Shape* s {CPP2_UFCS(get)((*cpp2::impl::assert_not_null(cpp2::move(c))))}; // safe by Lifetime + print(" +s* is Shape? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); + print( "s* is Circle? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); + print( "s* is Square? ", cpp2::impl::is(*cpp2::impl::assert_not_null(cpp2::move(s)))); + + +diff --git a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +index 17021ed..cfefcc2 100644 +--- a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +@@ -5,7 +5,7 @@ pure2-assert-expected-not-null.cpp2:7:10: error: no member named 'expected' in n + std::expected ex {4}; + ~~~~~^~~~~~~~ + unexpected +-/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here + void unexpected() __attribute__ ((__noreturn__)); + ^ + pure2-assert-expected-not-null.cpp2:9:193: error: use of undeclared identifier 'ex' +@@ -18,7 +18,7 @@ pure2-assert-expected-not-null.cpp2:14:10: error: no member named 'expected' in + std::expected ex {std::unexpected(false)}; + ~~~~~^~~~~~~~ + unexpected +-/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here + void unexpected() __attribute__ ((__noreturn__)); + ^ + pure2-assert-expected-not-null.cpp2:15:52: error: use of undeclared identifier 'ex' + + +diff --git a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +index 850cfc6..7dbfcb5 100644 +--- a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution ++++ b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +@@ -9,4 +9,4 @@ g0g0g + pl(ug$h + 0pl(ug$h + Dog kennel color mauve price 3.14 in stock = true +-Dog kennel color mauve price 3.14 in stock = true ++Dog kennel color mauve price 3.140000 in stock = true + + +diff --git a/regression-tests/test-results/pure2-intro-example-three-loops.cpp b/regression-tests/test-results/pure2-intro-example-three-loops.cpp +index 500f293..ea0af88 100644 +--- a/regression-tests/test-results/pure2-intro-example-three-loops.cpp ++++ b/regression-tests/test-results/pure2-intro-example-three-loops.cpp +@@ -45,7 +45,12 @@ auto decorate_and_print(auto& thing) -> void{ + "hello", "big", "world"}; + std::span view {words}; + +- auto i {cpp2_new(0)}; ++ auto p_i {cpp2_new(0)}; ++ if ((!(p_i))) { ++ return 1; ++ } ++ auto i {*cpp2::impl::assert_not_null(cpp2::move(p_i))}; ++ + for( ; cpp2::impl::cmp_less(*cpp2::impl::assert_not_null(i),CPP2_UFCS(ssize)(view)); ++*cpp2::impl::assert_not_null(i) ) { + print(CPP2_ASSERT_IN_BOUNDS(view, *cpp2::impl::assert_not_null(i))); + } + + +diff --git a/regression-tests/test-results/pure2-last-use.cpp b/regression-tests/test-results/pure2-last-use.cpp +index 8d72435..ec663a6 100644 +--- a/regression-tests/test-results/pure2-last-use.cpp ++++ b/regression-tests/test-results/pure2-last-use.cpp +@@ -362,9 +362,9 @@ class issue_857_9: public issue_857_8 { + }; + + class issue_869_0 { +- public: explicit issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2); ++ public: explicit issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2); + #line 373 "pure2-last-use.cpp2" +- public: auto operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& ; ++ public: auto operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& ; + public: [[nodiscard]] auto operator<=>([[maybe_unused]] issue_869_0 const& that) const& -> std::strong_ordering = default; + public: issue_869_0([[maybe_unused]] issue_869_0 const& that); + +@@ -520,57 +520,57 @@ requires (!(std::copyable)) { return std::move(cpp2::move(x)); } + #line 9 "pure2-last-use.cpp2" + auto issue_313() -> void{ + // _ = :() -> std::vector = { +-// a := new(0); ++// a := new(0)*; + // return (a*, identity_copy(a)*); + // }; + // _ = :() -> std::vector = { +-// a := new(0); ++// a := new(0)*; + // return (a&**, identity_copy(a)*); + // }; + static_cast([]() mutable -> int{ +- auto a {cpp2_new(0)}; ++ auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(a)) + *cpp2::impl::assert_not_null(identity(a)); + +- auto b {cpp2_new(0)}; ++ auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b)); + +- auto c {cpp2_new(0)}; ++ auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(c)) ^ *cpp2::impl::assert_not_null(identity(c)); + }); + { +- auto a {cpp2_new(0)}; ++ auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; + *cpp2::impl::assert_not_null(identity(a)) = *cpp2::impl::assert_not_null(identity(a)); + +- auto b {cpp2_new(0)}; ++ auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; + int auto_1 {*cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b))}; + +- auto c {cpp2_new(0)}; ++ auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (*cpp2::impl::assert_not_null(identity(c)) * *cpp2::impl::assert_not_null(identity(c))) {} + +- auto d {cpp2_new(0)}; ++ auto d {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if ((*cpp2::impl::assert_not_null(identity(d)) - *cpp2::impl::assert_not_null(identity(d)))) {} + +- auto e {cpp2_new(0)}; ++ auto e {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast(cpp2::impl::is(e, (e))); + +- auto f {cpp2_new(0)}; ++ auto f {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast(cpp2::impl::is>(f));// OK? + +- auto g {cpp2_new(0)}; ++ auto g {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { *cpp2::impl::assert_not_null(identity(g)) + *cpp2::impl::assert_not_null(identity(g)) } ) + {} + +- auto h {cpp2_new(0)}; ++ auto h {*cpp2::impl::assert_not_null(cpp2_new(0))}; + while( *cpp2::impl::assert_not_null(identity(h)) + *cpp2::impl::assert_not_null(identity(h)) ) + {} + +- auto i {cpp2_new(0)}; ++ auto i {*cpp2::impl::assert_not_null(cpp2_new(0))}; + do {} while ( + *cpp2::impl::assert_not_null(identity(i)) + *cpp2::impl::assert_not_null(identity(i))); + +- auto j {cpp2_new(0)}; +- auto k {cpp2_new(0)}; ++ auto j {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ auto k {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast([&] () -> int { auto&& _expr = *cpp2::impl::assert_not_null(identity(j)) + *cpp2::impl::assert_not_null(identity(j)); + if (cpp2::impl::is(_expr, (*cpp2::impl::assert_not_null(identity(k)) + *cpp2::impl::assert_not_null(identity(k))))) { if constexpr( requires{0;} ) if constexpr( std::is_convertible_v ) return 0; else return int{}; else return int{}; } + else return 0; } +@@ -578,7 +578,7 @@ auto issue_313() -> void{ + + } + // { +-// a := new(0); ++// a := new(0)*; + // _ = :() identity(a$)* + identity(a$)*; + // } + } +@@ -613,7 +613,7 @@ auto issue_683(auto const& args) -> void{ + auto issue_825() -> void{ + static_cast([](std::unique_ptr b) mutable -> auto { return f_copy(std::move(cpp2::move(b))); }); + static_cast([](std::unique_ptr&& c) mutable -> auto { return f_copy(std::move(cpp2::move(c))); }); +- static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(cpp2_new(0))); ++ static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(*cpp2::impl::assert_not_null(cpp2_new(0)))); + } + + #line 120 "pure2-last-use.cpp2" +@@ -730,10 +730,10 @@ int gi {0}; + auto issue_857_9::g2() && -> void { f_inout(cpp2::move((*this)).c); } + + #line 373 "pure2-last-use.cpp2" +- issue_869_0::issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2){} ++ issue_869_0::issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2){} + #line 373 "pure2-last-use.cpp2" +- auto issue_869_0::operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& { +- return *this; } ++ auto issue_869_0::operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& { ++ return *this; } + + + issue_869_0::issue_869_0([[maybe_unused]] issue_869_0 const& that){} +@@ -781,13 +781,13 @@ issue_869_1::issue_869_1(issue_869_1 const& that) + } + #line 378 "pure2-last-use.cpp2" + [[nodiscard]] auto issue_869_2() -> issue_869_2_ret{ +- issue_869_1 res {}; CPP2_UFCS(set_i)(res, cpp2_new(0)); ++ issue_869_1 res {}; CPP2_UFCS(set_i)(res, *cpp2::impl::assert_not_null(cpp2_new(0))); + #line 379 "pure2-last-use.cpp2" + return res; } + #line 380 "pure2-last-use.cpp2" + auto issue_884() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + { + {f_inout(x); } +@@ -796,7 +796,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -807,7 +807,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -819,7 +819,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + if (true) { + static_cast(0); +@@ -832,7 +832,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -845,7 +845,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -858,7 +858,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -871,7 +871,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -884,7 +884,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -897,7 +897,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -910,7 +910,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_inout(x); +@@ -926,7 +926,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_inout(x); +@@ -942,7 +942,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -958,7 +958,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + if (true) { +@@ -971,7 +971,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + if (true) { +@@ -985,7 +985,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + } + else { +@@ -998,7 +998,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -1012,9 +1012,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + f_copy(std::move(cpp2::move(y))); + } +@@ -1029,9 +1029,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + else { + f_copy(std::move(cpp2::move(x))); +@@ -1041,7 +1041,7 @@ auto issue_884() -> void{ + else { + if (true) { + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(y))); + f_inout(x); + } +@@ -1051,9 +1051,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + else { + f_copy(std::move(cpp2::move(x))); +@@ -1061,7 +1061,7 @@ auto issue_884() -> void{ + } + } + else { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -1075,13 +1075,13 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } + else { + if (true) { +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -1094,10 +1094,10 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -1113,7 +1113,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + + if (true) { + f_inout(x); +@@ -1127,7 +1127,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + f_inout(x); +@@ -1193,9 +1193,9 @@ auto issue_888_1([[maybe_unused]] std::string unnamed_param_1, move_only_functio + + #line 784 "pure2-last-use.cpp2" + auto issue_890() -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + { +-auto const& x{cpp2_new(0)}; ++auto const& x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + // assert(identity_copy(x)* == 0); + #line 787 "pure2-last-use.cpp2" + if (cpp2::cpp2_default.is_active() && !(*cpp2::impl::assert_not_null(identity(x)) == 0) ) { cpp2::cpp2_default.report_violation(""); } +@@ -1224,13 +1224,13 @@ auto enum_0() -> void{ + } + #line 806 "pure2-last-use.cpp2" + auto enum_1() -> void{ +- auto max_value {cpp2_new(0)}; +- std::reference_wrapper const> min_value {cpp2::move(max_value)}; ++ auto max_value {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ std::reference_wrapper const> min_value {cpp2::move(max_value)}; + + // for (0) + // do (copy x) + // { +- // v := new(identity_copy(x)); ++ // v := new(identity_copy(x))*; + // if pred(v, min_value) { + // min_value = std::ref(identity(v)); // Not using 'else' will never move 'v'. + // } +@@ -1239,21 +1239,21 @@ auto enum_1() -> void{ + // } + // } + +- auto y {cpp2_new(false)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(false))}; + while( *cpp2::impl::assert_not_null(identity(y)) ) { +- auto v {cpp2_new(0)}; ++ auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(v))); + } + +- auto z {cpp2_new(false)}; ++ auto z {*cpp2::impl::assert_not_null(cpp2_new(false))}; + do { +- auto v {cpp2_new(0)}; ++ auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(v))); + } while ( *cpp2::impl::assert_not_null(identity(z))); + } + #line 834 "pure2-last-use.cpp2" + auto enum_2() -> void{ +- auto umax {cpp2_new(0)}; ++ auto umax {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (pred(umax)) { + } + else {if (pred(umax)) { +@@ -1299,14 +1299,14 @@ return std::move(p.value()); } + #line 875 "pure2-last-use.cpp2" + auto loops() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) + f_inout(x); + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) { do +@@ -1314,14 +1314,14 @@ auto loops() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) + if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(get)(x)) ) { cpp2::cpp2_default.report_violation(""); } + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -1337,10 +1337,10 @@ namespace captures { + + #line 915 "pure2-last-use.cpp2" + auto f() -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + auto id {[](auto const& x) mutable -> auto&& { return x; }}; +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (cpp2::cpp2_default.is_active() && !(&cpp2::move(id)(y) == &y) ) { cpp2::cpp2_default.report_violation(""); } + } + +@@ -1360,13 +1360,13 @@ auto f() -> void{ + #line 940 "pure2-last-use.cpp2" + auto g() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + static_cast([_0 = std::array auto { return identity(x); }(0)>()]() mutable -> auto { return _0; });// Fails on Clang 12 (lambda in unevaluated context). + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(cpp2::move(x)); + // _ = :() -> int = (:() x$*)$(); + }); +@@ -1377,7 +1377,7 @@ auto g() -> void{ + #line 956 "pure2-last-use.cpp2" + auto loops_and_captures() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { [](auto const& x) mutable -> auto { return x; } } ) +@@ -1385,7 +1385,7 @@ auto loops_and_captures() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + for ( + +@@ -1395,7 +1395,7 @@ auto loops_and_captures() -> void{ + }); + + // _ = :() = { +-// x := new(0); ++// x := new(0)*; + // for (:() x$*) + // do (_) + // { } +@@ -1405,10 +1405,10 @@ auto loops_and_captures() -> void{ + #line 994 "pure2-last-use.cpp2" + auto skip_hidden_names() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + { +-auto x{cpp2_new(0)}; ++auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + + #line 999 "pure2-last-use.cpp2" + f_copy(std::move(cpp2::move(x))); +@@ -1417,10 +1417,10 @@ auto x{cpp2_new(0)}; + }); + + // _ = :() = { +-// x := new(0); ++// x := new(0)*; + // _ = :() = { + // _ = x$; +-// x := new(1); ++// x := new(1)*; + // _ = :() = { + // _ = x$; + // }; +@@ -1429,8 +1429,8 @@ auto x{cpp2_new(0)}; + + static_cast([]() mutable -> void{ + { +-auto x{cpp2_new(0)}; +- // x := new(0); ++auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ // x := new(0)*; + // f_copy(x); + // for (0) + // do (copy x) +@@ -1443,7 +1443,7 @@ auto x{cpp2_new(0)}; + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + { + f_copy(std::move(cpp2::move(x))); +@@ -1453,10 +1453,10 @@ auto x{cpp2_new(0)}; + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + static_cast([]() mutable -> void{ +- static_assert(std::is_same_v>); ++ static_assert(std::is_same_v>); + using captures::x; + f_inout(x); + }); + + +diff --git a/regression-tests/test-results/clang-15/pure2-last-use.cpp.output b/regression-tests/test-results/clang-15/pure2-last-use.cpp.output +index e69de29..14dd077 100644 +--- a/regression-tests/test-results/clang-15/pure2-last-use.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-last-use.cpp.output +@@ -0,0 +1,34 @@ ++pure2-last-use.cpp2:142:5: error: no matching function for call to 'f_inout' ++ f_inout(cpp2::move(x)); ++ ^~~~~~~ ++pure2-last-use.cpp2:1:6: note: candidate function [with unnamed_param_1:auto = std::unique_ptr] not viable: expects an lvalue for 1st argument ++auto f_inout([[maybe_unused]] auto& unnamed_param_1) -> void{} ++ ^ ++pure2-last-use.cpp2:175:5: error: no matching function for call to 'f_inout' ++ f_inout(cpp2::move((*this)).b); ++ ^~~~~~~ ++pure2-last-use.cpp2:1:6: note: candidate function [with unnamed_param_1:auto = std::unique_ptr] not viable: expects an lvalue for 1st argument ++auto f_inout([[maybe_unused]] auto& unnamed_param_1) -> void{} ++ ^ ++pure2-last-use.cpp2:366:39: error: no matching function for call to 'f_inout' ++ auto issue_857_9::g0() && -> void { f_inout(cpp2::move((*this)).a); } ++ ^~~~~~~ ++pure2-last-use.cpp2:1:6: note: candidate function [with unnamed_param_1:auto = std::unique_ptr] not viable: expects an lvalue for 1st argument ++auto f_inout([[maybe_unused]] auto& unnamed_param_1) -> void{} ++ ^ ++pure2-last-use.cpp2:808:63: error: no matching constructor for initialization of 'std::reference_wrapper>' ++ std::reference_wrapper const> min_value {cpp2::move(max_value)}; ++ ^ ~~~~~~~~~~~~~~~~~~~~~~~ ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/refwrap.h:326:7: note: candidate constructor not viable: no known conversion from 'cpp2::owning_reference' to 'const std::reference_wrapper>' for 1st argument ++ reference_wrapper(const reference_wrapper&) = default; ++ ^ ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/refwrap.h:321:2: note: candidate template ignored: substitution failure [with _Up = cpp2::owning_reference, $1 = void, $2 = void]: call to deleted function '_S_fun' ++ reference_wrapper(_Up&& __uref) ++ ^ ++pure2-last-use.cpp2:949:5: error: no matching function for call to 'f_inout' ++ f_inout(cpp2::move(x)); ++ ^~~~~~~ ++pure2-last-use.cpp2:1:6: note: candidate function [with unnamed_param_1:auto = cpp2::owning_reference] not viable: expects an lvalue for 1st argument ++auto f_inout([[maybe_unused]] auto& unnamed_param_1) -> void{} ++ ^ ++5 errors generated. + + +diff --git a/regression-tests/test-results/pure2-new-basics.cpp2.output b/regression-tests/test-results/pure2-new-basics.cpp2.output +index 1be2648..cb7037c 100644 +--- a/regression-tests/test-results/pure2-new-basics.cpp2.output ++++ b/regression-tests/test-results/pure2-new-basics.cpp2.output +@@ -1,2 +1,3 @@ +-pure2-new-basics.cpp2... ok (all Cpp2, passes safety checks) ++pure2-new-basics.cpp2... ++pure2-new-basics.cpp2(40,9): error: invalid statement encountered inside a compound-statement (at 'move_test') + + + +diff --git a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output +index e69de29..4b68b87 100644 +--- a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output +@@ -0,0 +1,135 @@ ++pure2-new-basics.cpp2:33:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:33:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:34:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:34:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:36:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto c {*cpp2::assert_not_null(std::move(a))}; ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:37:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(c)); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:38:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(std::move(c)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:46:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:46:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:51:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:51:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:71:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:71:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:72:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:72:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:73:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:73:41: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:76:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:76:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++fatal error: too many errors emitted, stopping now [-ferror-limit=] ++20 errors generated. + + +diff --git a/regression-tests/test-results/mixed-type-safety-1.cpp b/regression-tests/test-results/mixed-type-safety-1.cpp +index f175980..20aecdc 100644 +--- a/regression-tests/test-results/mixed-type-safety-1.cpp ++++ b/regression-tests/test-results/mixed-type-safety-1.cpp +@@ -58,7 +58,7 @@ auto print(cpp2::impl::in msg, cpp2::impl::in b) -> void + print( "1 is int? ", cpp2::impl::is(1)); + + auto c {cpp2_new()}; // safe by construction +- Shape* s {CPP2_UFCS(get)(cpp2::move(c))}; // safe by Lifetime ++ Shape* s {CPP2_UFCS(get)((*cpp2::impl::assert_not_null(cpp2::move(c))))}; // safe by Lifetime + print(" +s* is Shape? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); + print( "s* is Circle? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); + print( "s* is Square? ", cpp2::impl::is(*cpp2::impl::assert_not_null(cpp2::move(s)))); + + +diff --git a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +index 17021ed..cfefcc2 100644 +--- a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +@@ -5,7 +5,7 @@ pure2-assert-expected-not-null.cpp2:7:10: error: no member named 'expected' in n + std::expected ex {4}; + ~~~~~^~~~~~~~ + unexpected +-/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here + void unexpected() __attribute__ ((__noreturn__)); + ^ + pure2-assert-expected-not-null.cpp2:9:193: error: use of undeclared identifier 'ex' +@@ -18,7 +18,7 @@ pure2-assert-expected-not-null.cpp2:14:10: error: no member named 'expected' in + std::expected ex {std::unexpected(false)}; + ~~~~~^~~~~~~~ + unexpected +-/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here ++/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here + void unexpected() __attribute__ ((__noreturn__)); + ^ + pure2-assert-expected-not-null.cpp2:15:52: error: use of undeclared identifier 'ex' + + +diff --git a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +index 850cfc6..7dbfcb5 100644 +--- a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution ++++ b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +@@ -9,4 +9,4 @@ g0g0g + pl(ug$h + 0pl(ug$h + Dog kennel color mauve price 3.14 in stock = true +-Dog kennel color mauve price 3.14 in stock = true ++Dog kennel color mauve price 3.140000 in stock = true + + +diff --git a/regression-tests/test-results/pure2-intro-example-three-loops.cpp b/regression-tests/test-results/pure2-intro-example-three-loops.cpp +index 500f293..c204473 100644 +--- a/regression-tests/test-results/pure2-intro-example-three-loops.cpp ++++ b/regression-tests/test-results/pure2-intro-example-three-loops.cpp +@@ -21,7 +21,7 @@ auto decorate_and_print(auto& thing) -> void; + + #line 10 "pure2-intro-example-three-loops.cpp2" + [[nodiscard]] auto main() -> int; +-#line 35 "pure2-intro-example-three-loops.cpp2" ++#line 31 "pure2-intro-example-three-loops.cpp2" + + #line 1 "pure2-intro-example-three-loops.cpp2" + +@@ -45,7 +45,8 @@ auto decorate_and_print(auto& thing) -> void{ + "hello", "big", "world"}; + std::span view {words}; + +- auto i {cpp2_new(0)}; ++ auto i {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ + for( ; cpp2::impl::cmp_less(*cpp2::impl::assert_not_null(i),CPP2_UFCS(ssize)(view)); ++*cpp2::impl::assert_not_null(i) ) { + print(CPP2_ASSERT_IN_BOUNDS(view, *cpp2::impl::assert_not_null(i))); + } + + +diff --git a/regression-tests/test-results/pure2-last-use.cpp b/regression-tests/test-results/pure2-last-use.cpp +index 8d72435..ec663a6 100644 +--- a/regression-tests/test-results/pure2-last-use.cpp ++++ b/regression-tests/test-results/pure2-last-use.cpp +@@ -362,9 +362,9 @@ class issue_857_9: public issue_857_8 { + }; + + class issue_869_0 { +- public: explicit issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2); ++ public: explicit issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2); + #line 373 "pure2-last-use.cpp2" +- public: auto operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& ; ++ public: auto operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& ; + public: [[nodiscard]] auto operator<=>([[maybe_unused]] issue_869_0 const& that) const& -> std::strong_ordering = default; + public: issue_869_0([[maybe_unused]] issue_869_0 const& that); + +@@ -520,57 +520,57 @@ requires (!(std::copyable)) { return std::move(cpp2::move(x)); } + #line 9 "pure2-last-use.cpp2" + auto issue_313() -> void{ + // _ = :() -> std::vector = { +-// a := new(0); ++// a := new(0)*; + // return (a*, identity_copy(a)*); + // }; + // _ = :() -> std::vector = { +-// a := new(0); ++// a := new(0)*; + // return (a&**, identity_copy(a)*); + // }; + static_cast([]() mutable -> int{ +- auto a {cpp2_new(0)}; ++ auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(a)) + *cpp2::impl::assert_not_null(identity(a)); + +- auto b {cpp2_new(0)}; ++ auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b)); + +- auto c {cpp2_new(0)}; ++ auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; + return *cpp2::impl::assert_not_null(identity(c)) ^ *cpp2::impl::assert_not_null(identity(c)); + }); + { +- auto a {cpp2_new(0)}; ++ auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; + *cpp2::impl::assert_not_null(identity(a)) = *cpp2::impl::assert_not_null(identity(a)); + +- auto b {cpp2_new(0)}; ++ auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; + int auto_1 {*cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b))}; + +- auto c {cpp2_new(0)}; ++ auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (*cpp2::impl::assert_not_null(identity(c)) * *cpp2::impl::assert_not_null(identity(c))) {} + +- auto d {cpp2_new(0)}; ++ auto d {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if ((*cpp2::impl::assert_not_null(identity(d)) - *cpp2::impl::assert_not_null(identity(d)))) {} + +- auto e {cpp2_new(0)}; ++ auto e {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast(cpp2::impl::is(e, (e))); + +- auto f {cpp2_new(0)}; ++ auto f {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast(cpp2::impl::is>(f));// OK? + +- auto g {cpp2_new(0)}; ++ auto g {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { *cpp2::impl::assert_not_null(identity(g)) + *cpp2::impl::assert_not_null(identity(g)) } ) + {} + +- auto h {cpp2_new(0)}; ++ auto h {*cpp2::impl::assert_not_null(cpp2_new(0))}; + while( *cpp2::impl::assert_not_null(identity(h)) + *cpp2::impl::assert_not_null(identity(h)) ) + {} + +- auto i {cpp2_new(0)}; ++ auto i {*cpp2::impl::assert_not_null(cpp2_new(0))}; + do {} while ( + *cpp2::impl::assert_not_null(identity(i)) + *cpp2::impl::assert_not_null(identity(i))); + +- auto j {cpp2_new(0)}; +- auto k {cpp2_new(0)}; ++ auto j {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ auto k {*cpp2::impl::assert_not_null(cpp2_new(0))}; + static_cast([&] () -> int { auto&& _expr = *cpp2::impl::assert_not_null(identity(j)) + *cpp2::impl::assert_not_null(identity(j)); + if (cpp2::impl::is(_expr, (*cpp2::impl::assert_not_null(identity(k)) + *cpp2::impl::assert_not_null(identity(k))))) { if constexpr( requires{0;} ) if constexpr( std::is_convertible_v ) return 0; else return int{}; else return int{}; } + else return 0; } +@@ -578,7 +578,7 @@ auto issue_313() -> void{ + + } + // { +-// a := new(0); ++// a := new(0)*; + // _ = :() identity(a$)* + identity(a$)*; + // } + } +@@ -613,7 +613,7 @@ auto issue_683(auto const& args) -> void{ + auto issue_825() -> void{ + static_cast([](std::unique_ptr b) mutable -> auto { return f_copy(std::move(cpp2::move(b))); }); + static_cast([](std::unique_ptr&& c) mutable -> auto { return f_copy(std::move(cpp2::move(c))); }); +- static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(cpp2_new(0))); ++ static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(*cpp2::impl::assert_not_null(cpp2_new(0)))); + } + + #line 120 "pure2-last-use.cpp2" +@@ -730,10 +730,10 @@ int gi {0}; + auto issue_857_9::g2() && -> void { f_inout(cpp2::move((*this)).c); } + + #line 373 "pure2-last-use.cpp2" +- issue_869_0::issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2){} ++ issue_869_0::issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2){} + #line 373 "pure2-last-use.cpp2" +- auto issue_869_0::operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& { +- return *this; } ++ auto issue_869_0::operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& { ++ return *this; } + + + issue_869_0::issue_869_0([[maybe_unused]] issue_869_0 const& that){} +@@ -781,13 +781,13 @@ issue_869_1::issue_869_1(issue_869_1 const& that) + } + #line 378 "pure2-last-use.cpp2" + [[nodiscard]] auto issue_869_2() -> issue_869_2_ret{ +- issue_869_1 res {}; CPP2_UFCS(set_i)(res, cpp2_new(0)); ++ issue_869_1 res {}; CPP2_UFCS(set_i)(res, *cpp2::impl::assert_not_null(cpp2_new(0))); + #line 379 "pure2-last-use.cpp2" + return res; } + #line 380 "pure2-last-use.cpp2" + auto issue_884() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + { + {f_inout(x); } +@@ -796,7 +796,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -807,7 +807,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -819,7 +819,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + if (true) { + static_cast(0); +@@ -832,7 +832,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -845,7 +845,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -858,7 +858,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -871,7 +871,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + static_cast(0); +@@ -884,7 +884,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -897,7 +897,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -910,7 +910,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_inout(x); +@@ -926,7 +926,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_inout(x); +@@ -942,7 +942,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -958,7 +958,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + if (true) { +@@ -971,7 +971,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + if (true) { +@@ -985,7 +985,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + } + else { +@@ -998,7 +998,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -1012,9 +1012,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + f_copy(std::move(cpp2::move(y))); + } +@@ -1029,9 +1029,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + else { + f_copy(std::move(cpp2::move(x))); +@@ -1041,7 +1041,7 @@ auto issue_884() -> void{ + else { + if (true) { + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(y))); + f_inout(x); + } +@@ -1051,9 +1051,9 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) {} + else { + f_copy(std::move(cpp2::move(x))); +@@ -1061,7 +1061,7 @@ auto issue_884() -> void{ + } + } + else { +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + f_copy(std::move(cpp2::move(x))); +@@ -1075,13 +1075,13 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } + else { + if (true) { +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -1094,10 +1094,10 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_inout(x); + } +@@ -1113,7 +1113,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + + if (true) { + f_inout(x); +@@ -1127,7 +1127,7 @@ auto issue_884() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + if (true) { + f_inout(x); +@@ -1193,9 +1193,9 @@ auto issue_888_1([[maybe_unused]] std::string unnamed_param_1, move_only_functio + + #line 784 "pure2-last-use.cpp2" + auto issue_890() -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + { +-auto const& x{cpp2_new(0)}; ++auto const& x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + // assert(identity_copy(x)* == 0); + #line 787 "pure2-last-use.cpp2" + if (cpp2::cpp2_default.is_active() && !(*cpp2::impl::assert_not_null(identity(x)) == 0) ) { cpp2::cpp2_default.report_violation(""); } +@@ -1224,13 +1224,13 @@ auto enum_0() -> void{ + } + #line 806 "pure2-last-use.cpp2" + auto enum_1() -> void{ +- auto max_value {cpp2_new(0)}; +- std::reference_wrapper const> min_value {cpp2::move(max_value)}; ++ auto max_value {*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ std::reference_wrapper const> min_value {cpp2::move(max_value)}; + + // for (0) + // do (copy x) + // { +- // v := new(identity_copy(x)); ++ // v := new(identity_copy(x))*; + // if pred(v, min_value) { + // min_value = std::ref(identity(v)); // Not using 'else' will never move 'v'. + // } +@@ -1239,21 +1239,21 @@ auto enum_1() -> void{ + // } + // } + +- auto y {cpp2_new(false)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(false))}; + while( *cpp2::impl::assert_not_null(identity(y)) ) { +- auto v {cpp2_new(0)}; ++ auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(v))); + } + +- auto z {cpp2_new(false)}; ++ auto z {*cpp2::impl::assert_not_null(cpp2_new(false))}; + do { +- auto v {cpp2_new(0)}; ++ auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(v))); + } while ( *cpp2::impl::assert_not_null(identity(z))); + } + #line 834 "pure2-last-use.cpp2" + auto enum_2() -> void{ +- auto umax {cpp2_new(0)}; ++ auto umax {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (pred(umax)) { + } + else {if (pred(umax)) { +@@ -1299,14 +1299,14 @@ return std::move(p.value()); } + #line 875 "pure2-last-use.cpp2" + auto loops() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) + f_inout(x); + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) { do +@@ -1314,14 +1314,14 @@ auto loops() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) + if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(get)(x)) ) { cpp2::cpp2_default.report_violation(""); } + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (true) { + f_copy(std::move(cpp2::move(x))); + } +@@ -1337,10 +1337,10 @@ namespace captures { + + #line 915 "pure2-last-use.cpp2" + auto f() -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + auto id {[](auto const& x) mutable -> auto&& { return x; }}; +- auto y {cpp2_new(0)}; ++ auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; + if (cpp2::cpp2_default.is_active() && !(&cpp2::move(id)(y) == &y) ) { cpp2::cpp2_default.report_violation(""); } + } + +@@ -1360,13 +1360,13 @@ auto f() -> void{ + #line 940 "pure2-last-use.cpp2" + auto g() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + static_cast([_0 = std::array auto { return identity(x); }(0)>()]() mutable -> auto { return _0; });// Fails on Clang 12 (lambda in unevaluated context). + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(cpp2::move(x)); + // _ = :() -> int = (:() x$*)$(); + }); +@@ -1377,7 +1377,7 @@ auto g() -> void{ + #line 956 "pure2-last-use.cpp2" + auto loops_and_captures() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + for ( + [[maybe_unused]] auto const& unnamed_param_1 : { [](auto const& x) mutable -> auto { return x; } } ) +@@ -1385,7 +1385,7 @@ auto loops_and_captures() -> void{ + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + for ( + +@@ -1395,7 +1395,7 @@ auto loops_and_captures() -> void{ + }); + + // _ = :() = { +-// x := new(0); ++// x := new(0)*; + // for (:() x$*) + // do (_) + // { } +@@ -1405,10 +1405,10 @@ auto loops_and_captures() -> void{ + #line 994 "pure2-last-use.cpp2" + auto skip_hidden_names() -> void{ + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + { +-auto x{cpp2_new(0)}; ++auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + + #line 999 "pure2-last-use.cpp2" + f_copy(std::move(cpp2::move(x))); +@@ -1417,10 +1417,10 @@ auto x{cpp2_new(0)}; + }); + + // _ = :() = { +-// x := new(0); ++// x := new(0)*; + // _ = :() = { + // _ = x$; +-// x := new(1); ++// x := new(1)*; + // _ = :() = { + // _ = x$; + // }; +@@ -1429,8 +1429,8 @@ auto x{cpp2_new(0)}; + + static_cast([]() mutable -> void{ + { +-auto x{cpp2_new(0)}; +- // x := new(0); ++auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; ++ // x := new(0)*; + // f_copy(x); + // for (0) + // do (copy x) +@@ -1443,7 +1443,7 @@ auto x{cpp2_new(0)}; + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_inout(x); + { + f_copy(std::move(cpp2::move(x))); +@@ -1453,10 +1453,10 @@ auto x{cpp2_new(0)}; + }); + + static_cast([]() mutable -> void{ +- auto x {cpp2_new(0)}; ++ auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; + f_copy(std::move(cpp2::move(x))); + static_cast([]() mutable -> void{ +- static_assert(std::is_same_v>); ++ static_assert(std::is_same_v>); + using captures::x; + f_inout(x); + }); + + +diff --git a/regression-tests/test-results/pure2-new-basics.cpp2.output b/regression-tests/test-results/pure2-new-basics.cpp2.output +index 1be2648..cb7037c 100644 +--- a/regression-tests/test-results/pure2-new-basics.cpp2.output ++++ b/regression-tests/test-results/pure2-new-basics.cpp2.output +@@ -1,2 +1,3 @@ +-pure2-new-basics.cpp2... ok (all Cpp2, passes safety checks) ++pure2-new-basics.cpp2... ++pure2-new-basics.cpp2(40,9): error: invalid statement encountered inside a compound-statement (at 'move_test') + + + +diff --git a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output +index e69de29..4b68b87 100644 +--- a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output ++++ b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output +@@ -0,0 +1,135 @@ ++pure2-new-basics.cpp2:33:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:33:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:34:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:34:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:36:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto c {*cpp2::assert_not_null(std::move(a))}; ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:37:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(c)); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:38:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(std::move(c)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:46:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:46:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:51:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:51:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:71:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:71:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:72:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:72:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:73:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:73:41: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:76:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++pure2-new-basics.cpp2:76:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? ++ CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed ++ ^~~~~~~~~~~~~~~~~~~~~ ++ cpp2::impl::assert_not_null ++../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here ++auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) ++ ^ ++fatal error: too many errors emitted, stopping now [-ferror-limit=] ++20 errors generated. + diff --git a/regression-tests/mixed-type-safety-1.cpp2 b/regression-tests/mixed-type-safety-1.cpp2 index d7fb8adf9..1fc22dfa3 100644 --- a/regression-tests/mixed-type-safety-1.cpp2 +++ b/regression-tests/mixed-type-safety-1.cpp2 @@ -29,7 +29,7 @@ main: () -> int = print( "1 is int? ", 1 is int ); c := new(); // safe by construction - s : * Shape = c.get(); // safe by Lifetime + s : * Shape = c*.get(); // safe by Lifetime print("\ns* is Shape? ", s* is Shape ); print( "s* is Circle? ", s* is Circle ); print( "s* is Square? ", s* is Square ); diff --git a/regression-tests/pure2-intro-example-three-loops.cpp2 b/regression-tests/pure2-intro-example-three-loops.cpp2 index aa51ea959..ecbbf4113 100644 --- a/regression-tests/pure2-intro-example-three-loops.cpp2 +++ b/regression-tests/pure2-intro-example-three-loops.cpp2 @@ -12,7 +12,12 @@ main: () -> int = { ( "hello", "big", "world" ); view: std::span = words; - i := new(0); + p_i := new(0); + if (!p_i) { + return 1; + } + i := (move p_i*); + while i* < view.ssize() next i*++ { print( view[i*] ); } diff --git a/regression-tests/pure2-last-use.cpp2 b/regression-tests/pure2-last-use.cpp2 index 6a9c657f6..bc53696ce 100644 --- a/regression-tests/pure2-last-use.cpp2 +++ b/regression-tests/pure2-last-use.cpp2 @@ -8,57 +8,57 @@ identity_copy: (move x) -> _ requires !std::copyable = (move x); issue_313: () = { // _ = :() -> std::vector = { -// a := new(0); +// a := new(0)*; // return (a*, identity_copy(a)*); // }; // _ = :() -> std::vector = { -// a := new(0); +// a := new(0)*; // return (a&**, identity_copy(a)*); // }; _ = :() -> int = { - a := new(0); + a := new(0)*; return identity(a)* + identity(a)*; - b := new(0); + b := new(0)*; return identity(b)* = identity(b)*; - c := new(0); + c := new(0)*; return identity(c)* ^ identity(c)*; }; { - a := new(0); + a := new(0)*; identity(a)* = identity(a)*; - b := new(0); + b := new(0)*; _: int = identity(b)* = identity(b)*; - c := new(0); + c := new(0)*; if identity(c)* * identity(c)* { } - d := new(0); + d := new(0)*; if (identity(d)* - identity(d)*) { } - e := new(0); + e := new(0)*; _ = e is (e); - f := new(0); + f := new(0)*; _ = f is std::type_identity_t; // OK? - g := new(0); + g := new(0)*; for (identity(g)* + identity(g)*) do (_) { } - h := new(0); + h := new(0)*; while identity(h)* + identity(h)* { } - i := new(0); + i := new(0)*; do { } while identity(i)* + identity(i)*; - j := new(0); - k := new(0); + j := new(0)*; + k := new(0)*; _ = inspect identity(j)* + identity(j)* -> int { is (identity(k)* + identity(k)*) = 0; is _ = 0; @@ -66,7 +66,7 @@ issue_313: () = { } // { -// a := new(0); +// a := new(0)*; // _ = :() identity(a$)* + identity(a$)*; // } } @@ -114,7 +114,7 @@ issue_683: (args) = { issue_825: () = { _ = :(copy b: std::unique_ptr) f_copy(move b); _ = :(move c: std::unique_ptr) f_copy(move c); - _ = :(forward d) f_copy(d);(new(0)); + _ = :(forward d) f_copy(d);(new(0)*); } issue_832: () = { @@ -370,16 +370,16 @@ issue_857_9: @struct type = { } issue_869_0: @value type = { - operator=: (out this, move _: std::unique_ptr) = { } + operator=: (out this, move _: cpp2::owning_reference) = { } } issue_869_1: @union type = { i: issue_869_0; } -issue_869_2: () -> (res: issue_869_1 = ()) = { res.set_i(new(0)); } +issue_869_2: () -> (res: issue_869_1 = ()) = { res.set_i(new(0)*); } issue_884: () = { _ = :() = { - x := new(0); + x := new(0)*; if true { } { { f_inout(x); } @@ -388,7 +388,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(move x); } @@ -399,7 +399,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_inout(x); } @@ -411,7 +411,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(move x); if true { _ = 0; @@ -424,7 +424,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(move x); @@ -437,7 +437,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { _ = 0; @@ -450,7 +450,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { _ = 0; @@ -463,7 +463,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { _ = 0; @@ -476,7 +476,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(move x); @@ -489,7 +489,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(move x); @@ -502,7 +502,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_inout(x); @@ -518,7 +518,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_inout(x); @@ -534,7 +534,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(move x); @@ -550,7 +550,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { if true { @@ -563,7 +563,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { if true { @@ -577,7 +577,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { } else { @@ -590,7 +590,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(move x); } @@ -604,9 +604,9 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { - y := new(0); + y := new(0)*; f_copy(move x); f_copy(move y); } @@ -621,9 +621,9 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { - y := new(0); + y := new(0)*; if true { } else { f_copy(move x); @@ -633,7 +633,7 @@ issue_884: () = { else { if true { if true { - y := new(0); + y := new(0)*; f_copy(move y); f_inout(x); } @@ -643,9 +643,9 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { - y := new(0); + y := new(0)*; if true { } else { f_copy(move x); @@ -653,7 +653,7 @@ issue_884: () = { } } else { - y := new(0); + y := new(0)*; if true { if true { f_copy(move x); @@ -667,13 +667,13 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(move x); } else { if true { - x := new(0); + x := new(0)*; if true { f_inout(x); } @@ -686,10 +686,10 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { - x := new(0); + x := new(0)*; if true { f_inout(x); } @@ -705,7 +705,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_inout(x); @@ -719,7 +719,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { f_inout(x); @@ -782,9 +782,9 @@ issue_888_1: (copy _: std::string, copy size: move_only_function) = { } issue_890: () = { - x := new(0); + x := new(0)*; // assert(identity_copy(x)* == 0); - (x := new(0)) assert(identity(x)* == 0); + (x := new(0)*) assert(identity(x)* == 0); } issue_962: (s: ::std::string) = { @@ -804,13 +804,13 @@ enum_0: () = { underlying_type = ""; } enum_1: () = { - max_value := new(0); - min_value: std::reference_wrapper> = max_value; + max_value := new(0)*; + min_value: std::reference_wrapper> = max_value; // for (0) // do (copy x) // { - // v := new(identity_copy(x)); + // v := new(identity_copy(x))*; // if pred(v, min_value) { // min_value = std::ref(identity(v)); // Not using 'else' will never move 'v'. // } @@ -819,20 +819,20 @@ enum_1: () = { // } // } - y := new(false); + y := new(false)*; while identity(y)* { - v := new(0); + v := new(0)*; f_copy(move v); } - z := new(false); + z := new(false)*; do { - v := new(0); + v := new(0)*; f_copy(move v); } while identity(z)*; } enum_2: () = { - umax := new(0); + umax := new(0)*; if pred(umax) { } else if pred(umax) { @@ -874,14 +874,14 @@ deferred_non_copyable_2: () -> (p: std::unique_ptr) = { loops: () = { _ = :() = { - x := new(0); + x := new(0)*; for (0) do (_) f_inout(x); }; _ = :() = { - x := new(0); + x := new(0)*; for (0) next f_inout(x) do (_) @@ -889,14 +889,14 @@ loops: () = { }; _ = :() = { - x := new(0); + x := new(0)*; for (0) do (_) assert(x.get()); }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(move x); } @@ -913,10 +913,10 @@ captures: namespace = { // Skip non captured name in function expression f: () = { - x := new(0); + x := new(0)*; f_copy(move x); id := :(x) -> forward _ = x; - y := new(0); + y := new(0)*; assert(id(y)& == y&); } @@ -939,13 +939,13 @@ t: @struct type = { g: () = { _ = :() = { - x := new(0); + x := new(0)*; f_copy(move x); _ = :() std::array()$; // Fails on Clang 12 (lambda in unevaluated context). }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); // _ = :() -> int = (:() x$*)$(); }; @@ -955,7 +955,7 @@ g: () = { loops_and_captures: () = { _ = :() = { - x := new(0); + x := new(0)*; f_copy(move x); for (:(x) x) do (_) @@ -963,7 +963,7 @@ loops_and_captures: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(move x); for (:() -> _ = { using captures::x; @@ -974,7 +974,7 @@ loops_and_captures: () = { }; // _ = :() = { -// x := new(0); +// x := new(0)*; // for (:() x$*) // do (_) // { } @@ -993,17 +993,17 @@ types: @struct type = { skip_hidden_names: () = { _ = :() = { - x := new(0); + x := new(0)*; f_copy(move x); - (copy x := new(0)) + (copy x := new(0)*) f_copy(move x); }; // _ = :() = { -// x := new(0); +// x := new(0)*; // _ = :() = { // _ = x$; -// x := new(1); +// x := new(1)*; // _ = :() = { // _ = x$; // }; @@ -1011,17 +1011,17 @@ skip_hidden_names: () = { // }; _ = :() = { - // x := new(0); + // x := new(0)*; // f_copy(x); // for (0) // do (copy x) // _ = identity_copy(x); - (copy x := new(0)) + (copy x := new(0)*) f_copy(move x); }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); { f_copy(move x); @@ -1031,10 +1031,10 @@ skip_hidden_names: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(move x); _ = :() = { - static_assert(std::is_same_v>); + static_assert(std::is_same_v>); using captures::x; f_inout(x); }; diff --git a/regression-tests/pure2-new-basics.cpp2 b/regression-tests/pure2-new-basics.cpp2 new file mode 100644 index 000000000..1be5078c4 --- /dev/null +++ b/regression-tests/pure2-new-basics.cpp2 @@ -0,0 +1,108 @@ +Movable : type = { + operator= : (out this) = {} + operator= : (out this, move that) = {} + test : (this) = {} +} + +Copyable : type = { + operator= : (out this) = {} + operator= : (out this, in that) = {} + test : (this) = {} +} + +call_test : (m : _) = { + m.test(); +} + +test_movable : () = { + a : Movable = (); + a.test(); + call_test(a); + + b : Movable = (move a); + b.test(); + call_test(b); + + //a.test(); // not allowed +} + +move_to : (move c : _) = { + call_test(c*); + c*.test(); +} + +test_movable_ref : () = { + a : _ = new(); + + if (a) { + a**.test(); + call_test(a**); + //b : _ = a**; // cannot create copy + move_to(move a*); + // a**.test(); // not allowed + } +} + +test_movable_ref_replace : () = { + a : _ = new(); + if (a) { + a**.test(); + } + + a = new(); + if (a) { + a**.test(); + } +} + +test_copyable : () = { + a : Copyable = (); + a.test(); + call_test(a); + + b : Copyable = a; + b.test(); + call_test(b); + + a.test(); // allowed +} + +test_copyable_ref : () = { + a : _ = new(); + + if (a) { + a**.test(); + call_test(a**); + b : _ = a**; // create copy + call_test(b); + b.test(); + a**.test(); // allowed + + c : _ = (move a*); // move owning reference from optional + call_test(c*); + c*.test(); + //a**.test(); // no longer allowed + } +} + +test_copyable_ref_replace : () = { + a : _ = new(); + if (a) { + a**.test(); + } + + a = new(); + if (a) { + a**.test(); + } +} + + +main: () = { + test_movable(); + test_movable_ref(); + test_movable_ref_replace(); + test_copyable(); + test_copyable_ref(); + test_copyable_ref_replace(); +} diff --git a/regression-tests/run-tests.sh b/regression-tests/run-tests.sh old mode 100644 new mode 100755 diff --git a/regression-tests/test-results/apple-clang-14/pure2-new-basics.cpp.execution b/regression-tests/test-results/apple-clang-14/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/apple-clang-14/pure2-new-basics.cpp.output b/regression-tests/test-results/apple-clang-14/pure2-new-basics.cpp.output new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/clang-12/pure2-new-basics.cpp.execution b/regression-tests/test-results/clang-12/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/clang-12/pure2-new-basics.cpp.output b/regression-tests/test-results/clang-12/pure2-new-basics.cpp.output new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output index 17021ed74..cfefcc2d4 100644 --- a/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output +++ b/regression-tests/test-results/clang-15/pure2-assert-expected-not-null.cpp.output @@ -5,7 +5,7 @@ pure2-assert-expected-not-null.cpp2:7:10: error: no member named 'expected' in n std::expected ex {4}; ~~~~~^~~~~~~~ unexpected -/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here +/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here void unexpected() __attribute__ ((__noreturn__)); ^ pure2-assert-expected-not-null.cpp2:9:193: error: use of undeclared identifier 'ex' @@ -18,7 +18,7 @@ pure2-assert-expected-not-null.cpp2:14:10: error: no member named 'expected' in std::expected ex {std::unexpected(false)}; ~~~~~^~~~~~~~ unexpected -/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/exception:107:8: note: 'unexpected' declared here +/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/exception:95:8: note: 'unexpected' declared here void unexpected() __attribute__ ((__noreturn__)); ^ pure2-assert-expected-not-null.cpp2:15:52: error: use of undeclared identifier 'ex' diff --git a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution index 850cfc6bf..7dbfcb544 100644 --- a/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution +++ b/regression-tests/test-results/clang-15/pure2-interpolation.cpp.execution @@ -9,4 +9,4 @@ g0g0g pl(ug$h 0pl(ug$h Dog kennel color mauve price 3.14 in stock = true -Dog kennel color mauve price 3.14 in stock = true +Dog kennel color mauve price 3.140000 in stock = true diff --git a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.execution b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output new file mode 100644 index 000000000..4b68b8797 --- /dev/null +++ b/regression-tests/test-results/clang-15/pure2-new-basics.cpp.output @@ -0,0 +1,135 @@ +pure2-new-basics.cpp2:33:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:33:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:34:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:34:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:36:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + auto c {*cpp2::assert_not_null(std::move(a))}; + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:37:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + call_test(*cpp2::assert_not_null(c)); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:38:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(std::move(c)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:46:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:46:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:51:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:51:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:71:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:71:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:72:20: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:72:43: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:73:18: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:73:41: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:76:27: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +pure2-new-basics.cpp2:76:50: error: no member named 'assert_not_null' in namespace 'cpp2'; did you mean 'cpp2::impl::assert_not_null'? + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed + ^~~~~~~~~~~~~~~~~~~~~ + cpp2::impl::assert_not_null +../../../include/cpp2util.h:513:6: note: 'cpp2::impl::assert_not_null' declared here +auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) + ^ +fatal error: too many errors emitted, stopping now [-ferror-limit=] +20 errors generated. diff --git a/regression-tests/test-results/clang-18/pure2-new-basics.cpp.execution b/regression-tests/test-results/clang-18/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/clang-18/pure2-new-basics.cpp.output b/regression-tests/test-results/clang-18/pure2-new-basics.cpp.output new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/gcc-10/pure2-new-basics.cpp.execution b/regression-tests/test-results/gcc-10/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/gcc-10/pure2-new-basics.cpp.output b/regression-tests/test-results/gcc-10/pure2-new-basics.cpp.output new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/gcc-13/pure2-new-basics.cpp.execution b/regression-tests/test-results/gcc-13/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/gcc-13/pure2-new-basics.cpp.output b/regression-tests/test-results/gcc-13/pure2-new-basics.cpp.output new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/mixed-type-safety-1.cpp b/regression-tests/test-results/mixed-type-safety-1.cpp index f175980cb..20aecdc22 100644 --- a/regression-tests/test-results/mixed-type-safety-1.cpp +++ b/regression-tests/test-results/mixed-type-safety-1.cpp @@ -58,7 +58,7 @@ auto print(cpp2::impl::in msg, cpp2::impl::in b) -> void print( "1 is int? ", cpp2::impl::is(1)); auto c {cpp2_new()}; // safe by construction - Shape* s {CPP2_UFCS(get)(cpp2::move(c))}; // safe by Lifetime + Shape* s {CPP2_UFCS(get)((*cpp2::impl::assert_not_null(cpp2::move(c))))}; // safe by Lifetime print("\ns* is Shape? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); print( "s* is Circle? ", cpp2::impl::is(*cpp2::impl::assert_not_null(s))); print( "s* is Square? ", cpp2::impl::is(*cpp2::impl::assert_not_null(cpp2::move(s)))); diff --git a/regression-tests/test-results/msvc-2022/pure2-new-basics.cpp.execution b/regression-tests/test-results/msvc-2022/pure2-new-basics.cpp.execution new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/msvc-2022/pure2-new-basics.cpp.output b/regression-tests/test-results/msvc-2022/pure2-new-basics.cpp.output new file mode 100644 index 000000000..e69de29bb diff --git a/regression-tests/test-results/pure2-intro-example-three-loops.cpp b/regression-tests/test-results/pure2-intro-example-three-loops.cpp index 9a0689cb0..c20447340 100644 --- a/regression-tests/test-results/pure2-intro-example-three-loops.cpp +++ b/regression-tests/test-results/pure2-intro-example-three-loops.cpp @@ -21,7 +21,7 @@ auto decorate_and_print(auto& thing) -> void; #line 10 "pure2-intro-example-three-loops.cpp2" [[nodiscard]] auto main() -> int; -#line 30 "pure2-intro-example-three-loops.cpp2" +#line 31 "pure2-intro-example-three-loops.cpp2" #line 1 "pure2-intro-example-three-loops.cpp2" @@ -45,7 +45,8 @@ auto decorate_and_print(auto& thing) -> void{ "hello", "big", "world"}; std::span view {words}; - auto i {cpp2_new(0)}; + auto i {*cpp2::impl::assert_not_null(cpp2_new(0))}; + for( ; cpp2::impl::cmp_less(*cpp2::impl::assert_not_null(i),CPP2_UFCS(ssize)(view)); ++*cpp2::impl::assert_not_null(i) ) { print(CPP2_ASSERT_IN_BOUNDS(view, *cpp2::impl::assert_not_null(i))); } diff --git a/regression-tests/test-results/pure2-last-use.cpp b/regression-tests/test-results/pure2-last-use.cpp index 8d72435df..ec663a6ea 100644 --- a/regression-tests/test-results/pure2-last-use.cpp +++ b/regression-tests/test-results/pure2-last-use.cpp @@ -362,9 +362,9 @@ class issue_857_9: public issue_857_8 { }; class issue_869_0 { - public: explicit issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2); + public: explicit issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2); #line 373 "pure2-last-use.cpp2" - public: auto operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& ; + public: auto operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& ; public: [[nodiscard]] auto operator<=>([[maybe_unused]] issue_869_0 const& that) const& -> std::strong_ordering = default; public: issue_869_0([[maybe_unused]] issue_869_0 const& that); @@ -520,57 +520,57 @@ requires (!(std::copyable)) { return std::move(cpp2::move(x)); } #line 9 "pure2-last-use.cpp2" auto issue_313() -> void{ // _ = :() -> std::vector = { -// a := new(0); +// a := new(0)*; // return (a*, identity_copy(a)*); // }; // _ = :() -> std::vector = { -// a := new(0); +// a := new(0)*; // return (a&**, identity_copy(a)*); // }; static_cast([]() mutable -> int{ - auto a {cpp2_new(0)}; + auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; return *cpp2::impl::assert_not_null(identity(a)) + *cpp2::impl::assert_not_null(identity(a)); - auto b {cpp2_new(0)}; + auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; return *cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b)); - auto c {cpp2_new(0)}; + auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; return *cpp2::impl::assert_not_null(identity(c)) ^ *cpp2::impl::assert_not_null(identity(c)); }); { - auto a {cpp2_new(0)}; + auto a {*cpp2::impl::assert_not_null(cpp2_new(0))}; *cpp2::impl::assert_not_null(identity(a)) = *cpp2::impl::assert_not_null(identity(a)); - auto b {cpp2_new(0)}; + auto b {*cpp2::impl::assert_not_null(cpp2_new(0))}; int auto_1 {*cpp2::impl::assert_not_null(identity(b)) = *cpp2::impl::assert_not_null(identity(b))}; - auto c {cpp2_new(0)}; + auto c {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (*cpp2::impl::assert_not_null(identity(c)) * *cpp2::impl::assert_not_null(identity(c))) {} - auto d {cpp2_new(0)}; + auto d {*cpp2::impl::assert_not_null(cpp2_new(0))}; if ((*cpp2::impl::assert_not_null(identity(d)) - *cpp2::impl::assert_not_null(identity(d)))) {} - auto e {cpp2_new(0)}; + auto e {*cpp2::impl::assert_not_null(cpp2_new(0))}; static_cast(cpp2::impl::is(e, (e))); - auto f {cpp2_new(0)}; + auto f {*cpp2::impl::assert_not_null(cpp2_new(0))}; static_cast(cpp2::impl::is>(f));// OK? - auto g {cpp2_new(0)}; + auto g {*cpp2::impl::assert_not_null(cpp2_new(0))}; for ( [[maybe_unused]] auto const& unnamed_param_1 : { *cpp2::impl::assert_not_null(identity(g)) + *cpp2::impl::assert_not_null(identity(g)) } ) {} - auto h {cpp2_new(0)}; + auto h {*cpp2::impl::assert_not_null(cpp2_new(0))}; while( *cpp2::impl::assert_not_null(identity(h)) + *cpp2::impl::assert_not_null(identity(h)) ) {} - auto i {cpp2_new(0)}; + auto i {*cpp2::impl::assert_not_null(cpp2_new(0))}; do {} while ( *cpp2::impl::assert_not_null(identity(i)) + *cpp2::impl::assert_not_null(identity(i))); - auto j {cpp2_new(0)}; - auto k {cpp2_new(0)}; + auto j {*cpp2::impl::assert_not_null(cpp2_new(0))}; + auto k {*cpp2::impl::assert_not_null(cpp2_new(0))}; static_cast([&] () -> int { auto&& _expr = *cpp2::impl::assert_not_null(identity(j)) + *cpp2::impl::assert_not_null(identity(j)); if (cpp2::impl::is(_expr, (*cpp2::impl::assert_not_null(identity(k)) + *cpp2::impl::assert_not_null(identity(k))))) { if constexpr( requires{0;} ) if constexpr( std::is_convertible_v ) return 0; else return int{}; else return int{}; } else return 0; } @@ -578,7 +578,7 @@ auto issue_313() -> void{ } // { -// a := new(0); +// a := new(0)*; // _ = :() identity(a$)* + identity(a$)*; // } } @@ -613,7 +613,7 @@ auto issue_683(auto const& args) -> void{ auto issue_825() -> void{ static_cast([](std::unique_ptr b) mutable -> auto { return f_copy(std::move(cpp2::move(b))); }); static_cast([](std::unique_ptr&& c) mutable -> auto { return f_copy(std::move(cpp2::move(c))); }); - static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(cpp2_new(0))); + static_cast([](auto&& d) mutable -> auto { return f_copy(CPP2_FORWARD(d)); }(*cpp2::impl::assert_not_null(cpp2_new(0)))); } #line 120 "pure2-last-use.cpp2" @@ -730,10 +730,10 @@ int gi {0}; auto issue_857_9::g2() && -> void { f_inout(cpp2::move((*this)).c); } #line 373 "pure2-last-use.cpp2" - issue_869_0::issue_869_0([[maybe_unused]] std::unique_ptr&& unnamed_param_2){} + issue_869_0::issue_869_0([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2){} #line 373 "pure2-last-use.cpp2" - auto issue_869_0::operator=([[maybe_unused]] std::unique_ptr&& unnamed_param_2) -> issue_869_0& { - return *this; } + auto issue_869_0::operator=([[maybe_unused]] cpp2::owning_reference&& unnamed_param_2) -> issue_869_0& { + return *this; } issue_869_0::issue_869_0([[maybe_unused]] issue_869_0 const& that){} @@ -781,13 +781,13 @@ issue_869_1::issue_869_1(issue_869_1 const& that) } #line 378 "pure2-last-use.cpp2" [[nodiscard]] auto issue_869_2() -> issue_869_2_ret{ - issue_869_1 res {}; CPP2_UFCS(set_i)(res, cpp2_new(0)); + issue_869_1 res {}; CPP2_UFCS(set_i)(res, *cpp2::impl::assert_not_null(cpp2_new(0))); #line 379 "pure2-last-use.cpp2" return res; } #line 380 "pure2-last-use.cpp2" auto issue_884() -> void{ static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) {} { {f_inout(x); } @@ -796,7 +796,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_copy(std::move(cpp2::move(x))); } @@ -807,7 +807,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_inout(x); } @@ -819,7 +819,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); if (true) { static_cast(0); @@ -832,7 +832,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { f_copy(std::move(cpp2::move(x))); @@ -845,7 +845,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { static_cast(0); @@ -858,7 +858,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { static_cast(0); @@ -871,7 +871,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { static_cast(0); @@ -884,7 +884,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { f_copy(std::move(cpp2::move(x))); @@ -897,7 +897,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { f_copy(std::move(cpp2::move(x))); @@ -910,7 +910,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { f_inout(x); @@ -926,7 +926,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { f_inout(x); @@ -942,7 +942,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); if (true) { f_copy(std::move(cpp2::move(x))); @@ -958,7 +958,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { if (true) { if (true) { @@ -971,7 +971,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { if (true) { if (true) { @@ -985,7 +985,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { } else { @@ -998,7 +998,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_copy(std::move(cpp2::move(x))); } @@ -1012,9 +1012,9 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { - auto y {cpp2_new(0)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); f_copy(std::move(cpp2::move(y))); } @@ -1029,9 +1029,9 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { - auto y {cpp2_new(0)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) {} else { f_copy(std::move(cpp2::move(x))); @@ -1041,7 +1041,7 @@ auto issue_884() -> void{ else { if (true) { if (true) { - auto y {cpp2_new(0)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(y))); f_inout(x); } @@ -1051,9 +1051,9 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { - auto y {cpp2_new(0)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) {} else { f_copy(std::move(cpp2::move(x))); @@ -1061,7 +1061,7 @@ auto issue_884() -> void{ } } else { - auto y {cpp2_new(0)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { if (true) { f_copy(std::move(cpp2::move(x))); @@ -1075,13 +1075,13 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_copy(std::move(cpp2::move(x))); } else { if (true) { - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_inout(x); } @@ -1094,10 +1094,10 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { if (true) { - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_inout(x); } @@ -1113,7 +1113,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_inout(x); @@ -1127,7 +1127,7 @@ auto issue_884() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { if (true) { f_inout(x); @@ -1193,9 +1193,9 @@ auto issue_888_1([[maybe_unused]] std::string unnamed_param_1, move_only_functio #line 784 "pure2-last-use.cpp2" auto issue_890() -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; { -auto const& x{cpp2_new(0)}; +auto const& x{*cpp2::impl::assert_not_null(cpp2_new(0))}; // assert(identity_copy(x)* == 0); #line 787 "pure2-last-use.cpp2" if (cpp2::cpp2_default.is_active() && !(*cpp2::impl::assert_not_null(identity(x)) == 0) ) { cpp2::cpp2_default.report_violation(""); } @@ -1224,13 +1224,13 @@ auto enum_0() -> void{ } #line 806 "pure2-last-use.cpp2" auto enum_1() -> void{ - auto max_value {cpp2_new(0)}; - std::reference_wrapper const> min_value {cpp2::move(max_value)}; + auto max_value {*cpp2::impl::assert_not_null(cpp2_new(0))}; + std::reference_wrapper const> min_value {cpp2::move(max_value)}; // for (0) // do (copy x) // { - // v := new(identity_copy(x)); + // v := new(identity_copy(x))*; // if pred(v, min_value) { // min_value = std::ref(identity(v)); // Not using 'else' will never move 'v'. // } @@ -1239,21 +1239,21 @@ auto enum_1() -> void{ // } // } - auto y {cpp2_new(false)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(false))}; while( *cpp2::impl::assert_not_null(identity(y)) ) { - auto v {cpp2_new(0)}; + auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(v))); } - auto z {cpp2_new(false)}; + auto z {*cpp2::impl::assert_not_null(cpp2_new(false))}; do { - auto v {cpp2_new(0)}; + auto v {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(v))); } while ( *cpp2::impl::assert_not_null(identity(z))); } #line 834 "pure2-last-use.cpp2" auto enum_2() -> void{ - auto umax {cpp2_new(0)}; + auto umax {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (pred(umax)) { } else {if (pred(umax)) { @@ -1299,14 +1299,14 @@ return std::move(p.value()); } #line 875 "pure2-last-use.cpp2" auto loops() -> void{ static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; for ( [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) f_inout(x); }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; for ( [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) { do @@ -1314,14 +1314,14 @@ auto loops() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; for ( [[maybe_unused]] auto const& unnamed_param_1 : { 0 } ) if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(get)(x)) ) { cpp2::cpp2_default.report_violation(""); } }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (true) { f_copy(std::move(cpp2::move(x))); } @@ -1337,10 +1337,10 @@ namespace captures { #line 915 "pure2-last-use.cpp2" auto f() -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); auto id {[](auto const& x) mutable -> auto&& { return x; }}; - auto y {cpp2_new(0)}; + auto y {*cpp2::impl::assert_not_null(cpp2_new(0))}; if (cpp2::cpp2_default.is_active() && !(&cpp2::move(id)(y) == &y) ) { cpp2::cpp2_default.report_violation(""); } } @@ -1360,13 +1360,13 @@ auto f() -> void{ #line 940 "pure2-last-use.cpp2" auto g() -> void{ static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); static_cast([_0 = std::array auto { return identity(x); }(0)>()]() mutable -> auto { return _0; });// Fails on Clang 12 (lambda in unevaluated context). }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(cpp2::move(x)); // _ = :() -> int = (:() x$*)$(); }); @@ -1377,7 +1377,7 @@ auto g() -> void{ #line 956 "pure2-last-use.cpp2" auto loops_and_captures() -> void{ static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); for ( [[maybe_unused]] auto const& unnamed_param_1 : { [](auto const& x) mutable -> auto { return x; } } ) @@ -1385,7 +1385,7 @@ auto loops_and_captures() -> void{ }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); for ( @@ -1395,7 +1395,7 @@ auto loops_and_captures() -> void{ }); // _ = :() = { -// x := new(0); +// x := new(0)*; // for (:() x$*) // do (_) // { } @@ -1405,10 +1405,10 @@ auto loops_and_captures() -> void{ #line 994 "pure2-last-use.cpp2" auto skip_hidden_names() -> void{ static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); { -auto x{cpp2_new(0)}; +auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; #line 999 "pure2-last-use.cpp2" f_copy(std::move(cpp2::move(x))); @@ -1417,10 +1417,10 @@ auto x{cpp2_new(0)}; }); // _ = :() = { -// x := new(0); +// x := new(0)*; // _ = :() = { // _ = x$; -// x := new(1); +// x := new(1)*; // _ = :() = { // _ = x$; // }; @@ -1429,8 +1429,8 @@ auto x{cpp2_new(0)}; static_cast([]() mutable -> void{ { -auto x{cpp2_new(0)}; - // x := new(0); +auto x{*cpp2::impl::assert_not_null(cpp2_new(0))}; + // x := new(0)*; // f_copy(x); // for (0) // do (copy x) @@ -1443,7 +1443,7 @@ auto x{cpp2_new(0)}; }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_inout(x); { f_copy(std::move(cpp2::move(x))); @@ -1453,10 +1453,10 @@ auto x{cpp2_new(0)}; }); static_cast([]() mutable -> void{ - auto x {cpp2_new(0)}; + auto x {*cpp2::impl::assert_not_null(cpp2_new(0))}; f_copy(std::move(cpp2::move(x))); static_cast([]() mutable -> void{ - static_assert(std::is_same_v>); + static_assert(std::is_same_v>); using captures::x; f_inout(x); }); diff --git a/regression-tests/test-results/pure2-new-basics.cpp b/regression-tests/test-results/pure2-new-basics.cpp new file mode 100644 index 000000000..1e4edcc67 --- /dev/null +++ b/regression-tests/test-results/pure2-new-basics.cpp @@ -0,0 +1,194 @@ + +#define CPP2_IMPORT_STD Yes + +//=== Cpp2 type declarations ==================================================== + + +#include "cpp2util.h" + +#line 1 "pure2-new-basics.cpp2" +class Movable; +#line 2 "pure2-new-basics.cpp2" + + +#line 7 "pure2-new-basics.cpp2" +class Copyable; + + +//=== Cpp2 type definitions and function declarations =========================== + +#line 1 "pure2-new-basics.cpp2" +class Movable { +#line 2 "pure2-new-basics.cpp2" + public: explicit Movable(); + public: Movable([[maybe_unused]] Movable&& that) noexcept; +#line 3 "pure2-new-basics.cpp2" + public: auto operator=([[maybe_unused]] Movable&& that) noexcept -> Movable& ; + public: auto test() const& -> void; +}; + +class Copyable { + public: explicit Copyable(); + public: Copyable([[maybe_unused]] Copyable const& that); +#line 9 "pure2-new-basics.cpp2" + public: auto operator=([[maybe_unused]] Copyable const& that) -> Copyable& ; +#line 9 "pure2-new-basics.cpp2" + public: Copyable([[maybe_unused]] Copyable&& that) noexcept; +#line 9 "pure2-new-basics.cpp2" + public: auto operator=([[maybe_unused]] Copyable&& that) noexcept -> Copyable& ; + public: auto test() const& -> void; +}; + +auto call_test(auto const& m) -> void; + +#line 17 "pure2-new-basics.cpp2" +auto test_movable() -> void; + +#line 29 "pure2-new-basics.cpp2" +auto test_movable_ref() -> void; + +#line 43 "pure2-new-basics.cpp2" +auto test_movable_ref_replace() -> void; + +#line 55 "pure2-new-basics.cpp2" +auto test_copyable() -> void; + +#line 67 "pure2-new-basics.cpp2" +auto test_copyable_ref() -> void; + +#line 85 "pure2-new-basics.cpp2" +auto test_copyable_ref_replace() -> void; + +#line 98 "pure2-new-basics.cpp2" +auto main() -> int; + +//=== Cpp2 function definitions ================================================= + +#line 1 "pure2-new-basics.cpp2" + +#line 2 "pure2-new-basics.cpp2" + Movable::Movable(){} +#line 3 "pure2-new-basics.cpp2" + Movable::Movable([[maybe_unused]] Movable&& that) noexcept{} +#line 3 "pure2-new-basics.cpp2" + auto Movable::operator=([[maybe_unused]] Movable&& that) noexcept -> Movable& { + return *this; } +#line 4 "pure2-new-basics.cpp2" + auto Movable::test() const& -> void{} + +#line 8 "pure2-new-basics.cpp2" + Copyable::Copyable(){} +#line 9 "pure2-new-basics.cpp2" + Copyable::Copyable([[maybe_unused]] Copyable const& that){} +#line 9 "pure2-new-basics.cpp2" + auto Copyable::operator=([[maybe_unused]] Copyable const& that) -> Copyable& { + return *this; } +#line 9 "pure2-new-basics.cpp2" + Copyable::Copyable([[maybe_unused]] Copyable&& that) noexcept{} +#line 9 "pure2-new-basics.cpp2" + auto Copyable::operator=([[maybe_unused]] Copyable&& that) noexcept -> Copyable& { + return *this; } +#line 10 "pure2-new-basics.cpp2" + auto Copyable::test() const& -> void{} + +#line 13 "pure2-new-basics.cpp2" +auto call_test(auto const& m) -> void{ + CPP2_UFCS(test)(m); +} + +#line 17 "pure2-new-basics.cpp2" +auto test_movable() -> void{ + Movable a {}; + CPP2_UFCS(test)(a); + call_test(a); + + Movable b {std::move(a)}; + CPP2_UFCS(test)(b); + call_test(std::move(b)); + + //a.test(); // not allowed +} + +#line 29 "pure2-new-basics.cpp2" +auto test_movable_ref() -> void{ + auto a {cpp2_new()}; + + if ((a)) { + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); + //b : _ = a**; // cannot create copy + auto c {*cpp2::assert_not_null(std::move(a))}; + call_test(*cpp2::assert_not_null(c)); + CPP2_UFCS(test)((*cpp2::assert_not_null(std::move(c)))); + // a**.test(); // not allowed + } +} + +#line 43 "pure2-new-basics.cpp2" +auto test_movable_ref_replace() -> void{ + auto a {cpp2_new()}; + if ((a)) { + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + } + + a = cpp2_new(); + if ((a)) { + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); + } +} + +#line 55 "pure2-new-basics.cpp2" +auto test_copyable() -> void{ + Copyable a {}; + CPP2_UFCS(test)(a); + call_test(a); + + Copyable b {a}; + CPP2_UFCS(test)(b); + call_test(std::move(b)); + + CPP2_UFCS(test)(std::move(a));// allowed +} + +#line 67 "pure2-new-basics.cpp2" +auto test_copyable_ref() -> void{ + auto a {cpp2_new()}; + + if ((a)) { + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + call_test(*cpp2::assert_not_null(*cpp2::assert_not_null(a))); + auto b {*cpp2::assert_not_null(*cpp2::assert_not_null(a))}; // create copy + call_test(b); + CPP2_UFCS(test)(std::move(b)); + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a))));// allowed + + auto c {*cpp2::assert_not_null(std::move(a))}; // move owning reference from optional + call_test(*cpp2::assert_not_null(c)); + CPP2_UFCS(test)((*cpp2::assert_not_null(std::move(c)))); + //a**.test(); // no longer allowed + } +} + +#line 85 "pure2-new-basics.cpp2" +auto test_copyable_ref_replace() -> void{ + auto a {cpp2_new()}; + if ((a)) { + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(a)))); + } + + a = cpp2_new(); + if ((a)) { + CPP2_UFCS(test)((*cpp2::assert_not_null(*cpp2::assert_not_null(std::move(a))))); + } +} + +#line 98 "pure2-new-basics.cpp2" +auto main() -> int{ + test_movable(); + test_movable_ref(); + test_movable_ref_replace(); + test_copyable(); + test_copyable_ref(); + test_copyable_ref_replace(); +} + diff --git a/regression-tests/test-results/pure2-new-basics.cpp2.output b/regression-tests/test-results/pure2-new-basics.cpp2.output new file mode 100644 index 000000000..cb7037ccc --- /dev/null +++ b/regression-tests/test-results/pure2-new-basics.cpp2.output @@ -0,0 +1,3 @@ +pure2-new-basics.cpp2... +pure2-new-basics.cpp2(40,9): error: invalid statement encountered inside a compound-statement (at 'move_test') +