Bug 17932 – [scope] __traits(compiles, stmt) cannot test scope violations

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-23T20:12:41Z
Last change time
2018-03-11T23:53:29Z
Keywords
safe
Assigned to
Walter Bright
Creator
Martin Nowak

Comments

Comment #0 by code — 2017-10-23T20:12:41Z
cat > bug.d << CODE void test() @safe { int var; scope int* p; static int* escape; static assert(!__traits(compiles, { escape = p; })); escape = p; } CODE dmd -c -dip1000 bug.d ---- bug.d(6): Error: static assert !true is false ---- The static assertion should pass as the assignment is not allowed. bug.d(7): Error: scope variable p assigned to non-scope escape
Comment #1 by bugzilla — 2018-03-11T23:53:29Z
Adding @safe to the lambda: void test() @safe { int var; scope int* p; static int* escape; static assert(!__traits(compiles, () @safe { escape = p; })); // escape = p; } and it compiles without error. The lambda does not inherit @safe from the function. Perhaps it should, but that would be an enhancement request, and would possibly break existing code. It should be the subject of a separate issue.