mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Add defaults to compare_exchange, small fix in printf. Disallow obviously wrong code that returns the pointer to a variable on the stack.
This commit is contained in:
40
test/test_suite/safe/detect_invalid_deref_return.c3
Normal file
40
test/test_suite/safe/detect_invalid_deref_return.c3
Normal file
@@ -0,0 +1,40 @@
|
||||
fn int[] test1()
|
||||
{
|
||||
int[3] x;
|
||||
return &x; // #error: local variable will be invalid
|
||||
}
|
||||
|
||||
fn int* test2()
|
||||
{
|
||||
int[3] x;
|
||||
return &x[0]; // #error: local variable will be invalid
|
||||
}
|
||||
|
||||
struct Abc
|
||||
{
|
||||
int a;
|
||||
int[3] b;
|
||||
}
|
||||
|
||||
fn int* test3()
|
||||
{
|
||||
Abc x;
|
||||
return &x.a; // #error: local variable will be invalid
|
||||
}
|
||||
|
||||
fn int* test4()
|
||||
{
|
||||
Abc x;
|
||||
return &x.b; // #error: local variable will be invalid
|
||||
}
|
||||
|
||||
fn int* test5()
|
||||
{
|
||||
Abc x;
|
||||
return &x.b[0]; // #error: local variable will be invalid
|
||||
}
|
||||
|
||||
fn int* test6()
|
||||
{
|
||||
return &&1; // #error: temporary value will
|
||||
}
|
||||
Reference in New Issue
Block a user