String copying fails when output from assert

Adam D. Ruppe destructionator at gmail.com
Tue Nov 21 18:56:03 UTC 2017


On Tuesday, 21 November 2017 at 18:49:40 UTC, David  Zhang wrote:
> 	assert(false, chars[0..str.length]);
> }
>
> What am I missing here?

You're escaping a reference to a local variable there. chars[] is 
a pointer to the stack, which is promptly smashed when the assert 
error starts working up the call chain, so by the time it 
actually prints, you have undefined behavior.


More information about the Digitalmars-d-learn mailing list