add compile error for returning local variable address

closes #344
This commit is contained in:
Andrew Kelley
2017-04-27 19:40:35 -04:00
parent 1691074b4b
commit 2e512a0e6e
4 changed files with 28 additions and 2 deletions

View File

@@ -1610,4 +1610,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
,
".tmp_source.zig:3:5: error: cannot set section of external function 'foo'",
".tmp_source.zig:1:8: note: declared here");
cases.add("returning address of local variable",
\\export fn foo() -> &i32 {
\\ var a: i32 = undefined;
\\ return &a;
\\}
,
".tmp_source.zig:3:13: error: function returns address of local variable");
}