www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21098] New: poor diagnostic when trying to assign a `string`

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 puremagic.com
          Reporter: b2.temp 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. --
Jul 30 2020