]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/cleanup-shortcircuit.rs
auto merge of #11230 : csherratt/rust/cow, r=alexcrichton
[rust.git] / src / test / run-pass / cleanup-shortcircuit.rs
1 // copyright 2014 the rust project developers. see the copyright
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/copyright.
4 //
5 // licensed under the apache license, version 2.0 <license-apache or
6 // http://www.apache.org/licenses/license-2.0> or the mit license
7 // <license-mit or http://opensource.org/licenses/mit>, at your
8 // option. this file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that cleanups for the RHS of shorcircuiting operators work.
12
13 use std::{os, run};
14 use std::io::process;
15
16 pub fn main() {
17     let args = os::args();
18
19     // Here, the rvalue `~"signal"` requires cleanup. Older versions
20     // of the code had a problem that the cleanup scope for this
21     // expression was the end of the `if`, and as the `~"signal"`
22     // expression was never evaluated, we wound up trying to clean
23     // uninitialized memory.
24
25     if args.len() >= 2 && args[1] == ~"signal" {
26         // Raise a segfault.
27         unsafe { *(0 as *mut int) = 0; }
28     }
29 }
30