Thread overview
[Issue 21190] generated strings should convert to immutable char *
Sep 17, 2020
RazvanN
Sep 18, 2020
RazvanN
Dec 17, 2022
Iain Buclaw
September 17, 2020
https://issues.dlang.org/show_bug.cgi?id=21190

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Steven Schveighoffer from comment #0)
> When a string is generated at compile time (and assigned to an enum), it should be equivalent to a string literal in all cases.
> 
> This works today:
> 
> enum x = "hello";
> const char *p = x;
> enum x2 = "hello" ~ " there";
> p = x2;
> static string foo()
> {
>    return "hello" ~ " there";
> }
> 
> enum x3 = foo();
> p = x3;
> 
> This does not:
> 
> static string foo2()
> {
>    import std.string : join;
>    return ["hello", "there"].join(" ");
> }
> 
> enum x4 = foo2();
> p = x4; // Error: cannot implicitly convert expression "hello there" of type
> string to const(char*)
> 
> It's unclear why foo2 cannot produce a convertible string, whereas all the other cases can.

Are you sure this is the correct code? I just tried running the following example:

enum x = "hello";
const char *p = x;
enum x2 = "hello" ~ " there";

static string foo()
{
   return "hello" ~ " there";
}

enum x3 = foo();

static string foo2()
{
   import std.string : join;
   return ["hello", "there"].join(" ");
}

enum x4 = foo2();

void goo()
{
    p = x2;
    p = x3;
    p = x4;
}

And I get errors to all three assignments of p.

--
September 17, 2020
https://issues.dlang.org/show_bug.cgi?id=21190

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
oof! Yeah, it's not valid, but the bug is still valid. Change p declaration to:

const(char)* p = x;

and you now see the single error for the assignment to x4.

--
September 18, 2020
https://issues.dlang.org/show_bug.cgi?id=21190

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Steven Schveighoffer from comment #2)
> oof! Yeah, it's not valid, but the bug is still valid. Change p declaration to:
> 
> const(char)* p = x;
> 
> and you now see the single error for the assignment to x4.

Yeah, it's definitely a bug. And a weird one also.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=21190

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=21190

--- Comment #4 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17984

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--