[Issue 10724] Allow slice of string literal to convert to const(char)*

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 16 21:33:07 PDT 2013


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



--- Comment #8 from yebblies <yebblies at gmail.com> 2013-10-17 15:33:06 EST ---
(In reply to comment #7)
> The following used not to work in v2.063.2:
> 
>     const a = "a";
>     const b = a ~ "b";
>     const(char)* output = b;
> 
>     $ Error: cannot implicitly convert expression ("ab") of type
> const(immutable(char)[]) to const(char)*
> 
> Although this worked:
> 
>     const b = "a" ~ "b";
>     const(char)* output = b;
> 
> Now both work. I assume it was the fix for this issue (10724) that also fixed
> this? I say fixed because at first glance the old behavior seems wrong, but it
> seems such a basic statement that I wonder why this wasn't spotted before, or
> if I'm making a mistake. So please confirm this change in behavior was also
> desirable.

All this patch changed was the 'committing' behavior of SliceExp constfolding. 
Without a slice anywhere in there it doesn't look like this patch is the cause.

The code does appear to be valid as 'a' and 'b' are const variables with
initializers known at compile time, so the const-folder can determine that
'output' is assigned a string literal and allow the conversion.  I would expect
replacing any of them with a run-time determined value will prevent the
conversion.

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