[Issue 21098] New: poor diagnostic when trying to assign a `string` to a `char*`

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 31 06:10:50 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21098

          Issue ID: 21098
           Summary: poor diagnostic when trying to assign a `string` to a
                    `char*`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

the following code

---
void main()
{
    char* c;
    c = "";
}
---

fails to compile with the error

> /tmp/temp_7F155FF5EE70.d(8,9): Error: cannot implicitly convert expression `""` of type `string` to `char*`

which is correct. However the compiler could detect that the intent is correct
but that `c` must be of type `const(char)*` or `immutable(char)*` and emit a
supplemental message accordingly.

--


More information about the Digitalmars-d-bugs mailing list