You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for constructing variables in conditions
This change allows to initialize variables in `if` and `else if`
conditions. It make possible to process the following code:
```cpp
main: (args) = {
p : *int;
a := 1;
b := 2;
c := 3;
d := 4;
if args.cout == 3 {
p = a&;
} else if args.cout == 2 {
p = c&;
} else if p = b& {
p = a&;
}
else {
p = d&;
}
std::cout << p* << std::endl;
}
```
And gets generated:
```cpp
auto main(int const argc_, char const* const* const argv_) -> int{
auto args = cpp2::make_args(argc_, argv_);
#line 2 "tests/else_if.cpp2"
cpp2::deferred_init<int*> p;
auto a {1};
auto b {2};
auto c {3};
auto d {4};
if (args.cout==3) {
p.construct(&a);
} else if (args.cout==2) {
p.construct(&c);
} else if (p.construct(&b)) {
p.value() = &a;
}
else {
p.value() = &d;
}
std::cout << *cpp2::assert_not_null(std::move(p.value())) << std::endl;
}
```
0 commit comments