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 e9c3584
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,26 @@ final class CParser(AST) : Parser!AST
isalias = false;
}
}
else if (auto tt = dt.isTypeTag())
{
/* `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)
;
}

0 comments on commit e9c3584

Please sign in to comment.