www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21190] New: generated strings should convert to immutable


          Issue ID: 21190
           Summary: generated strings should convert to immutable char *
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schveiguy yahoo.com

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.

Aug 22 2020