Skip to content

Commit

Permalink
copy elision example
Browse files Browse the repository at this point in the history
---
Signed-off-by: Brandon Neth <[email protected]>
  • Loading branch information
brandon-neth committed Jan 3, 2024
1 parent afbe602 commit 7b4170d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/rst/language/spec/variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,23 @@ Copy elision does not apply:
}
elideCopyBothConditional();
proc elideCopyParamSelect() {
type T = int;
var x = makeRecord();
var y = x; // copy elided
select T {
when real {
writeln(x);
}
when string {
writeln(x);
}
otherwise {
writeln(y); // compiler can determine this is the only possible branch
}
}
}
elideCopyParamSelect();
.. BLOCK-test-chapeloutput
init (default)
Expand All @@ -1146,5 +1163,7 @@ Copy elision does not apply:
init (default)
block ending
deinit 0
init (default)
deinit 0

0 comments on commit 7b4170d

Please sign in to comment.