Bug 22250 – ImportC: Array subscripts do not comply with C standard.
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-30T02:50:27Z
Last change time
2021-09-30T01:46:01Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
mhh
Comments
Comment #0 by maxhaton — 2021-08-30T02:50:27Z
As per (C11) 6.5.2.1: "A postfix expression followed by an expression in square brackets [] is a subscripted
designation of an element of an array object. The definition of the subscript operator []
is that E1[E2] is identical to (*((E1)+(E2)))."
As such the following should compile:
---
int main()
{
char staticArray[256];
char squoze = 2[staticArray];
}
---
currently fails with
Error: cannot use `[]` operator on expression of type `int`
I doubt much C code actually uses this but supporting it could prove a useful exercise in supporting C semantics properly rather than kind of bullying a valid C parse into the dmd AST.
Comment #1 by dlang-bot — 2021-09-04T06:48:24Z
@WalterBright created dlang/dmd pull request #13045 "fix Issue 22250 - ImportC: Array subscripts do not comply with C stan…" fixing this issue:
- fix Issue 22250 - ImportC: Array subscripts do not comply with C standard
https://github.com/dlang/dmd/pull/13045
Comment #2 by dlang-bot — 2021-09-10T06:15:38Z
dlang/dmd pull request #13045 "fix Issue 22250 - ImportC: Array subscripts do not comply with C stan…" was merged into stable:
- f3b9e3dd2d630b1c014754b23c9586ee99a21f89 by Walter Bright:
fix Issue 22250 - ImportC: Array subscripts do not comply with C standard
https://github.com/dlang/dmd/pull/13045
Comment #3 by dlang-bot — 2021-09-30T01:46:01Z
dlang/dmd pull request #13108 "merge stable" was merged into master:
- 4fabb86680bafce06725dd93793fd806a0df5138 by Walter Bright:
fix Issue 22250 - ImportC: Array subscripts do not comply with C standard
https://github.com/dlang/dmd/pull/13108