Jump to page: 1 2 3
Thread overview
[Issue 4539] New: Refuse assignment to string literal
Jul 31, 2010
Andrej Mitrovic
Jul 31, 2010
Andrej Mitrovic
Aug 01, 2010
Don
Aug 01, 2010
nfxjfg@gmail.com
Apr 27, 2011
Kenji Hara
Apr 29, 2011
kennytm@gmail.com
Jun 05, 2011
Walter Bright
Jun 05, 2011
Kenji Hara
Jul 01, 2011
yebblies
Sep 05, 2011
yebblies
Dec 13, 2011
yebblies
Dec 25, 2011
Denis
Dec 25, 2011
Kenji Hara
Jan 29, 2012
Walter Bright
Jan 29, 2012
Kenji Hara
Jan 30, 2012
Andrej Mitrovic
July 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539

           Summary: Refuse assignment to string literal
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-07-31 04:26:35 PDT ---
dmd 2.047 compiles this code, but string literals can't be lvalues:

void main() {
    "hello" = "red";
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-07-31 07:27:57 PDT ---
I just found this by accident on the compiler docs page:

http://www.digitalmars.com/d/2.0/dmd-windows.html

"
Differences between Windows and Linux versions

    * String literals are read-only under Linux. Attempting to write to them
will cause a segment violation.
"

Maybe this is relevant?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539



--- Comment #2 from bearophile_hugs@eml.cc 2010-07-31 08:48:12 PDT ---
I think that's not relevant, I think that refers to changing the content of a variable initialized with a string literal (plus cast to mutable).

But the code I have shown is meaningless, because a string can't be a lvalue. It's like doing:

void main() {
    5 = 7;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-07-31 09:18:53 PDT ---
Yeah, it does not make sense at all. But it gets worse:

import std.stdio;

void main() {
    "hello" = "red";
    string x = "hello";
    writeln(x);
}

Writes "red"

That's not good. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
           Severity|normal                      |major


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-07-31 17:30:23 PDT ---
(In reply to comment #3)
> Yeah, it does not make sense at all. But it gets worse:
> 
> import std.stdio;
> 
> void main() {
>     "hello" = "red";
>     string x = "hello";
>     writeln(x);
> }
> 
> Writes "red"
> 
> That's not good. :)

Ouch!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg@gmail.com


--- Comment #5 from nfxjfg@gmail.com 2010-07-31 18:43:05 PDT ---
This segfaults on the far superior Linux (dmd v2.046), so yes, it's probably because OPTLINK can't do read-only sections.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4539



--- Comment #6 from bearophile_hugs@eml.cc 2010-10-29 09:55:19 PDT ---
A related bug found by denis spir:

auto p = &"hello";

String literals aren't lvalues, so you can't take their address. Just as you can't tale the address of a decimal literal:

auto q = &(1);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4539


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |k.hara.pg@gmail.com


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2011-04-27 04:16:32 PDT ---
Patch posted: https://github.com/D-Programming-Language/dmd/pull/46

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4539


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@kyllingen.net


--- Comment #8 from kennytm@gmail.com 2011-04-29 07:04:05 PDT ---
*** Issue 4309 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4539


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> 2011-06-04 22:55:03 PDT ---
(In reply to comment #7)
> Patch posted: https://github.com/D-Programming-Language/dmd/pull/46

See github for problems with the patch.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3