Bug 18003 – assert performs implicit conversion of mutable local static char array to string

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-11-21T19:29:00Z
Last change time
2017-11-21T19:33:06Z
Assigned to
No Owner
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2017-11-21T19:29:00Z
Code: ------ void f() { char[6] err = "Argh!"; assert(0, err[0 .. $]); } void main() { f(); } ------ In the assert output, the message is garbled because it's a slice of the local variable `err`, which has gone out of scope by the time the error message is displayed. Expected behaviour: assert() should not allow mutable char[] as second argument, or the compiler should not allow implicit conversion of a mutable char[] slice to immutable(char)[].
Comment #1 by hsteoh — 2017-11-21T19:31:39Z
P.S. Marking both functions as @safe and compiling with -dip25 and -dip1000 also fails to catch this leak of a reference to a local variable outside f().
Comment #2 by hsteoh — 2017-11-21T19:33:06Z
*** This issue has been marked as a duplicate of issue 18002 ***