On Borrow Checking
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sun May 18 00:42:51 UTC 2025
Further proof that clang can do more than what DIP1000 can:
``$clang --analyze``
```c++
void assign(int* input [[clang::lifetime_capture_by(output)]], int**
output) {
*output = input;
}
int* global;
void grab() {
int var;
assign(&var, &global);
}
```
Output:
```
<source>:9:5: warning: Address of stack memory associated with local
variable 'var' is still referred to by the global variable 'global' upon
returning to the caller. This will be a dangling reference
[core.StackAddressEscape]
8 | int var;
| ~~~~~~~
9 | assign(&var, &global);
| ^~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
https://godbolt.org/z/nY518WqTr
More information about the Digitalmars-d
mailing list