[Issue 4539] Refuse assignment to string literal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 29 15:20:56 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=4539



--- Comment #18 from Kenji Hara <k.hara.pg at gmail.com> 2012-01-29 15:20:53 PST ---
(In reply to comment #17)
> With the latest DMD2.058head this code:
> 
> 
> void foo(immutable ref string) {}
> void main() {
>     foo("hello");
> }
> 
> 
> Gives:
> 
> test.d(3): Error: function test.foo (ref immutable(char[]) _param_0) is not
> callable using argument types (string)
> 
> Is this expected?
> 
> (Also note the function signature is (ref immutable(char[]) _param_0) while I
> have specified an immutable ref).

Yes, it is expected behavior.
'ref' storage class requires lvalue slice in this case, but string literal
DOESN'T have slice, because it has only content.

Instead, you can get a reference to string literal by `ref immutable(char[5])`
or `ref const(char[5])` (5 == "hello".length), they bind just only content.

-- 
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