[Issue 22221] New: [dip1000] pure function can escape parameters through Exception
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 18 15:44:44 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22221
Issue ID: 22221
Summary: [dip1000] pure function can escape parameters through
Exception
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: safe, Vision
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
Follow up to issue 20150. The fix for that issue prevented escaping through the
return value, but had the known limitation that even when escaping through
parameters or the return value is not possible, parameters of pure functions
can still be put into an Exception and thrown:
```
void f_throw(string x) @safe pure
{
throw new Exception(x);
}
void escape_throw_20150() @safe
{
immutable(char)[4] str;
f_throw(str[]);
}
```
If the function isn't `nothrow`, the pure function -> scope parameters
implication shouldn't be done.
--
More information about the Digitalmars-d-bugs
mailing list