Bug 4309 – String literal passed by ref causes segfault

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-06-14T05:20:00Z
Last change time
2011-04-29T07:04:04Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2010-06-14T05:20:01Z
The following compiles, but causes a segmentation fault when run: void foo(ref string s) { s = "hello yourself"; // Anything that changes s will do. } void main() { foo("hello"); } I'm guessing that the compiler should catch this and provide an error saying "hello" is not an lvalue. At least that's what it does if one tries something similar with an array literal.
Comment #1 by lio+bugzilla — 2010-07-15T07:03:05Z
You're lucky if it segfaults. On Windows, it changes my literals, even dupped ones: --------- refs.d void X(ref string s) { assert(s[0] == 'a'); s = s[1..$]; } void main() { X("ab"); X("ab"); } core.exception.AssertError@refs(3): Assertion failure Digital Mars D Compiler v2.047
Comment #2 by bugzilla — 2010-11-29T05:03:02Z
*** Issue 5289 has been marked as a duplicate of this issue. ***
Comment #3 by kennytm — 2011-04-29T07:04:04Z
This problem arises because a string literal *is* treated as an lvalue currently. *** This issue has been marked as a duplicate of issue 4539 ***