Skip to content

Commit

Permalink
fix Issue 21963 - importC: Support declaring union types
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed May 26, 2021
1 parent b602a1d commit 2453350
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -2743,7 +2743,7 @@ final class CParser(AST) : Parser!AST
* declarator (opt) : constant-expression
*
* Params:
* symbols = symbols to add enum declaration to
* symbols = symbols to add struct-or-union declaration to
* Returns:
* type of the struct
*/
Expand All @@ -2760,7 +2760,11 @@ final class CParser(AST) : Parser!AST
nextToken();
}

auto stag = new AST.StructDeclaration(loc, tag, false);
assert(structOrUnion.value == TOK.struct_ || structOrUnion.value == TOK.union_);
auto stag = (structOrUnion.value == TOK.struct_)
? new AST.StructDeclaration(loc, tag, false)
: new AST.UnionDeclaration(loc, tag);

if (!symbols)
symbols = new AST.Dsymbols();
symbols.push(stag);
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/tokens.d
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ static immutable TOK[TOK.max + 1] Ckeywords =
enum Ckwds = [ auto_, break_, case_, char_, const_, continue_, default_, do_, float64, else_,
enum_, extern_, float32, for_, goto_, if_, inline, int32, int64, register,
restrict, return_, int16, signed, sizeof_, static_, struct_, switch_, typedef_,
unsigned, void_, volatile, while_, asm_,
union_, unsigned, void_, volatile, while_, asm_,
_Alignas, _Alignof, _Atomic, _Bool, _Complex, _Generic, _Imaginary, _Noreturn,
_Static_assert, _Thread_local, __cdecl, __restrict, __declspec, __attribute__ ];

Expand Down
8 changes: 8 additions & 0 deletions test/compilable/imports/cstuff1.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ typedef enum {
} TypedefEnum;
TypedefEnum typedef_var2;

/********************************/
// https://issues.dlang.org/show_bug.cgi?id=21963
union union_type
{
int iv;
float fv;
};

/********************************/
// https://issues.dlang.org/show_bug.cgi?id=21967
const int const_int_fn(void);
Expand Down

0 comments on commit 2453350

Please sign in to comment.