Bug 22070 – importC: Error: string/array literal is not an lvalue
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-22T19:31:54Z
Last change time
2022-09-20T04:50:54Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-06-22T19:31:54Z
It is an lvalue in C
"""
6.5.1-4: A string literal is a primary expression. It is an lvalue with type as detailed in 6.4.5.
"""
Reduced test
---
char(*var)[4] = &"123";
Comment #1 by bugzilla — 2021-07-17T08:05:20Z
Interestingly, dmc rejects it, too, with cannot take the address of a string.
Comment #2 by dlang-bot — 2021-07-18T09:15:29Z
@WalterBright created dlang/dmd pull request #12888 "Issue 22070 - importC: Error: string literal is not an lvalue" mentioning this issue:
- Issue 22070 - importC: Error: string literal is not an lvalue
https://github.com/dlang/dmd/pull/12888
Comment #3 by dlang-bot — 2021-07-19T08:23:49Z
@WalterBright created dlang/dmd pull request #12889 "fix Issue 22070 - importC: Error: string literal is not an lvalue" fixing this issue:
- fix Issue 22070 - importC: Error: string literal is not an lvalue
https://github.com/dlang/dmd/pull/12889
Comment #4 by dlang-bot — 2021-07-22T08:44:27Z
dlang/dmd pull request #12889 "fix Issue 22070 - importC: Error: string literal is not an lvalue" was merged into master:
- 9a377cbe666a669eee67ebc9d26796249cf4e488 by Walter Bright:
fix Issue 22070 - importC: Error: string literal is not an lvalue
https://github.com/dlang/dmd/pull/12889
Comment #5 by me — 2022-04-26T09:30:59Z
This also applies to array literals, per 6.5.2.5-4:
> In either case [array or object], the result is an lvalue.
```
short(*v1)[2] = &(short[]){1, 2};
```
Object literals act as lvalues as expected.
Additionally, the following invalid code is now accepted:
```
char(**s1)[3] = &(&"aa");
char(***s2)[3] = &(&(&"aa"));
// and so on
```
Comment #6 by dlang-bot — 2022-04-26T16:36:11Z
@Yoplitein created dlang/dmd pull request #14028 "Expand fix for issue 22070 to also allow array literals as lvalues" mentioning this issue:
- Expand fix for issue 22070 to also allow array literals as lvalues
Check for and restrict nested address-of expressions on literals, such as `&(&"")`
https://github.com/dlang/dmd/pull/14028
Comment #7 by dlang-bot — 2022-04-27T06:02:50Z
dlang/dmd pull request #14028 "Expand fix for issue 22070 to also allow array literals as lvalues" was merged into master:
- 95f218d081b0695836f901b62f0b16bb68107449 by Steven Dwy:
Expand fix for issue 22070 to also allow array literals as lvalues
Check for and restrict nested address-of expressions on literals, such as `&(&"")`
https://github.com/dlang/dmd/pull/14028
Comment #8 by dlang-bot — 2022-05-01T11:39:50Z
@WalterBright updated dlang/dmd pull request #14049 "fix Issue 23057 - importC: dmd segfault on invalid syntax" mentioning this issue:
- Expand fix for issue 22070 to also allow array literals as lvalues
Check for and restrict nested address-of expressions on literals, such as `&(&"")`
https://github.com/dlang/dmd/pull/14049
Comment #9 by dlang-bot — 2022-05-02T03:12:01Z
@ljmf00 updated dlang/dmd pull request #14058 "fix(backend): define XMM load/store codegen for short type variants" mentioning this issue:
- Expand fix for issue 22070 to also allow array literals as lvalues
Check for and restrict nested address-of expressions on literals, such as `&(&"")`
https://github.com/dlang/dmd/pull/14058
Comment #10 by dlang-bot — 2022-05-09T00:51:27Z
@WalterBright updated dlang/dmd pull request #14044 "fix Issue 23058 - importC: cannot take address inside multi-dimension…" mentioning this issue:
- Expand fix for issue 22070 to also allow array literals as lvalues
Check for and restrict nested address-of expressions on literals, such as `&(&"")`
https://github.com/dlang/dmd/pull/14044
Comment #11 by bugzilla — 2022-09-15T07:16:33Z
(In reply to Steven Dwy from comment #5)
> This also applies to array literals, per 6.5.2.5-4:
> > In either case [array or object], the result is an lvalue.
Please do not reopen fixed bugs to report new bugs. If you find another bug, open another bugzilla issue.
Comment #12 by bugzilla — 2022-09-20T04:50:54Z
As far as I can tell, this all works correctly with master.
If other issues are found, please do not reopen this. Open a new issue.