Bug 21098 – poor diagnostic when trying to assign a string literal to a `char*`
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-31T06:10:50Z
Last change time
2021-03-18T07:39:34Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2020-07-31T06:10:50Z
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.
Comment #1 by dlang-bot — 2020-08-21T08:37:52Z
@NilsLankila created dlang/dmd pull request #11602 "fix issue 21098 - Add specific diagnostic for failed assign from StringExp" fixing this issue:
- fix issue 21098 - Add specific diagnostic for failed assign from StringExp
Because assigning a literal to `char*` or a `char[]` is almost correct, add a supplemental error message that suggests to use a const/immtable type.
https://github.com/dlang/dmd/pull/11602
Comment #2 by b2.temp — 2021-03-18T07:39:34Z
The PR did not encounter much success and this is a minor problem anyway.