mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 13:40:11 +03:00
ImportC: can't access members in static array (#21185)
Fixes https://github.com/dlang/dmd/issues/20472 Arrays in C implicitly convert to a pointer to their first member, so do the implicit conversion when using them in an arrow member lookup.
This commit is contained in:
parent
7dd0506aaf
commit
ca2f90d1fc
3 changed files with 21 additions and 2 deletions
|
@ -126,6 +126,12 @@ Expression fieldLookup(Expression e, Scope* sc, Identifier id, bool arrow)
|
||||||
e = e.expressionSemantic(sc);
|
e = e.expressionSemantic(sc);
|
||||||
if (e.isErrorExp())
|
if (e.isErrorExp())
|
||||||
return e;
|
return e;
|
||||||
|
if (arrow)
|
||||||
|
{
|
||||||
|
e = arrayFuncConv(e, sc);
|
||||||
|
if (e.isErrorExp())
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
auto t = e.type;
|
auto t = e.type;
|
||||||
if (t.isTypePointer())
|
if (t.isTypePointer())
|
||||||
|
|
12
compiler/test/compilable/test20472.c
Normal file
12
compiler/test/compilable/test20472.c
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// https://github.com/dlang/dmd/issues/20472
|
||||||
|
typedef struct {
|
||||||
|
char c;
|
||||||
|
} stuff;
|
||||||
|
|
||||||
|
char test20472(void)
|
||||||
|
{
|
||||||
|
stuff s[1];
|
||||||
|
s->c = 1;
|
||||||
|
return s->c;
|
||||||
|
}
|
||||||
|
_Static_assert(test20472() == 1, "1");
|
|
@ -398,8 +398,9 @@ void* tests3()
|
||||||
|
|
||||||
int tests4()
|
int tests4()
|
||||||
{
|
{
|
||||||
struct S { int b; } a, *p;
|
struct S { int b; } a, *p, b[1];
|
||||||
a.b = 3;
|
b->b = 3;
|
||||||
|
a.b = b->b;
|
||||||
p = &a;
|
p = &a;
|
||||||
return p->b;
|
return p->b;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue