On Thursday, 16 March 2017 at 17:50:45 UTC, Adam D. Ruppe wrote:
string s = func()[]; // I'd allow it, at least the user wrote `[]` meaning they realized it was stack data and presumably knows what that means about the slice's lifetime

This explicit slice won't work, because a slice of a fixed size array results in a fixed size array.

There's no reason to allow this buggy code though. Also programmer didn't necessarily mean it. It could be a typographic error or a result of refactoring. Even if programmer wanted to write invalid code, what for? Yet this particular code doesn't need to be allowed to allow writing invalid code: one can still cast a number to pointer and do whatever he wants.

Reply via email to