forked from hsutter/cppfront
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpure2-initialization-safety-with-else-if.cpp
More file actions
65 lines (49 loc) · 1.62 KB
/
pure2-initialization-safety-with-else-if.cpp
File metadata and controls
65 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define CPP2_INCLUDE_STD Yes
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "pure2-initialization-safety-with-else-if.cpp2"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "pure2-initialization-safety-with-else-if.cpp2"
auto main(int const argc_, char** argv_) -> int;
#line 28 "pure2-initialization-safety-with-else-if.cpp2"
auto ok() -> void;
//=== Cpp2 function definitions =================================================
#line 1 "pure2-initialization-safety-with-else-if.cpp2"
auto main(int const argc_, char** argv_) -> int{
auto const args = cpp2::make_args(argc_, argv_);
#line 2 "pure2-initialization-safety-with-else-if.cpp2"
cpp2::impl::deferred_init<int*> p;
auto a {1};
auto b {2};
auto c {3};
auto d {4};
if (CPP2_UFCS(size)(args) == 3) {
p.construct(&a);
}else {if (true) {
if (CPP2_UFCS(size)(args) == 2) {
p.construct(&c);
}else {if (cpp2::impl::cmp_greater(cpp2::move(b),0)) {
p.construct(&a);
}
else {
p.construct(&d);
}}
}else {
p.construct(&c);
}}
std::cout << *cpp2::impl::assert_not_null(cpp2::move(p.value())) << std::endl;
}
#line 28 "pure2-initialization-safety-with-else-if.cpp2"
auto ok() -> void{
cpp2::impl::deferred_init<int> i;
if (true) {
i.construct(42);
while( true ) { // OK: in-branch loop is after initialization
i.value() = 42;
}
}
else {
i.construct(42);
}
i.value() = 42;
}