[Issue 4539] Refuse assignment to string literal
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Dec 25 07:30:00 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4539
--- Comment #15 from Kenji Hara <k.hara.pg at gmail.com> 2011-12-25 07:29:50 PST ---
Updated patch.
https://github.com/D-Programming-Language/dmd/pull/164
A string literal should be able to bind a reference to static array type.
In the context of ref binding, string literal should work as like static array
value.
Example:
void main()
{
void foo1(ref string s){} // ref slice
void foo2(ref const char[10] s){} // difference of length
void foo3(ref char[5] s){} // mutable element
void foo4(ref const char[5] s)
{
assert(s[0] == 'h');
assert(s[4] == 'o');
}
void foo5(ref const ubyte[5] s)
{
assert(s[0] == 0xc3);
assert(s[4] == 0x61);
}
static assert(!__traits(compiles, foo1("hello")));
static assert(!__traits(compiles, foo2("hello")));
static assert(!__traits(compiles, foo3("hello")));
foo4("hello");
foo5(cast(ubyte[5])x"c3fcd3d761");
import std.conv;
static assert(!__traits(compiles, parse!int("10") == 10));
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list