Skip to content

Commit

Permalink
fix Issue 22623 - ImportC: typedef'd struct definition tag not put in…
Browse files Browse the repository at this point in the history
… symbol table
  • Loading branch information
WalterBright committed Jan 23, 2022
1 parent a6e6708 commit ef8c229
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
23 changes: 23 additions & 0 deletions src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,29 @@ final class CParser(AST) : Parser!AST
isalias = false;
}
}
else if (auto tt = dt.isTypeTag())
{
if (tt.id)
{
/* `struct tag;` and `struct tag { ... };`
* always result in a declaration in the current scope
*/
auto stag = (tt.tok == TOK.struct_) ? new AST.StructDeclaration(tt.loc, tt.id, false) :
(tt.tok == TOK.union_) ? new AST.UnionDeclaration(tt.loc, tt.id) :
new AST.EnumDeclaration(tt.loc, tt.id, tt.base);
stag.members = tt.members;
if (!symbols)
symbols = new AST.Dsymbols();
symbols.push(stag);
if (tt.tok == TOK.enum_)
{
if (!tt.members)
error(tt.loc, "`enum %s` has no members", stag.toChars());
}
s = new AST.AliasDeclaration(token.loc, id, stag);
isalias = false;
}
}
if (isalias)
s = new AST.AliasDeclaration(token.loc, id, dt);
}
Expand Down
18 changes: 18 additions & 0 deletions test/compilable/fix22623.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://issues.dlang.org/show_bug.cgi?id=22623

struct S {
struct T *child;
};

typedef
struct T {
int xyz;
} U;

void fn()
{
struct S s;
struct T t;
if (s.child != &t)
;
}
21 changes: 1 addition & 20 deletions test/fail_compilation/failcstuff3.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// check importAll analysis of C files
/* TEST_OUTPUT:
---
fail_compilation/failcstuff3.c(54): Error: redeclaration of `S22061`
fail_compilation/failcstuff3.c(100): Error: can only `*` a pointer, not a `int`
fail_compilation/failcstuff3.c(157): Error: variable `failcstuff3.T22106.f1` no definition of struct `S22106_t`
fail_compilation/failcstuff3.c(54): Error: union `failcstuff3.S22061` conflicts with struct `failcstuff3.S22061` at fail_compilation/failcstuff3.c(50)
---
*/

Expand All @@ -16,20 +14,3 @@ struct S22061
};
typedef union S22061 S22061;

/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22103
#line 100
int test22103(int array[*4]);

/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22106
#line 150
typedef struct S22106
{
int field;
} S22106_t;

struct T22106
{
struct S22106_t f1;
};
25 changes: 25 additions & 0 deletions test/fail_compilation/failcstuff4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// check importAll analysis of C files
/* TEST_OUTPUT:
---
fail_compilation/failcstuff3.c(100): Error: can only `*` a pointer, not a `int`
fail_compilation/failcstuff3.c(157): Error: variable `failcstuff3.T22106.f1` no definition of struct `S22106_t`
---
*/

/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22103
#line 100
int test22103(int array[*4]);

/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22106
#line 150
typedef struct S22106
{
int field;
} S22106_t;

struct T22106
{
struct S22106_t f1;
};

0 comments on commit ef8c229

Please sign in to comment.