diff --git a/cl/type_and_var.go b/cl/type_and_var.go index 326c60c..c74e11c 100644 --- a/cl/type_and_var.go +++ b/cl/type_and_var.go @@ -76,16 +76,19 @@ func toStructType(ctx *blockCtx, t *types.Named, struc *ast.Node, pub bool) (ret decl := struc.Inner[i] switch decl.Kind { case ast.FieldDecl: + name := decl.Name if debugCompileDecl { - log.Println(" => field", decl.Name, "-", decl.Type.QualType) + log.Println(" => field", name, "-", decl.Type.QualType) + } + if name != "" { + checkFieldName(&name, pub) } - checkFieldName(&decl.Name, pub) typ, _ := toTypeEx(ctx, scope, nil, decl.Type, parser.FlagIsStructField) if decl.IsBitfield { bits := toInt64(ctx, decl.Inner[0], "non-constant bit field") - b.BitField(ctx, typ, decl.Name, int(bits)) + b.BitField(ctx, typ, name, int(bits)) } else { - b.Field(ctx, ctx.goNodePos(decl), typ, decl.Name, false) + b.Field(ctx, ctx.goNodePos(decl), typ, name, false) } case ast.RecordDecl: name, suKind := ctx.getSuName(decl, decl.TagUsed) @@ -127,12 +130,13 @@ func toUnionType(ctx *blockCtx, t *types.Named, unio *ast.Node, pub bool) (ret t decl := unio.Inner[i] switch decl.Kind { case ast.FieldDecl: + name := decl.Name if debugCompileDecl { - log.Println(" => field", decl.Name, "-", decl.Type.QualType) + log.Println(" => field", name, "-", decl.Type.QualType) } - checkFieldName(&decl.Name, pub) + checkFieldName(&name, pub) typ, _ := toTypeEx(ctx, scope, nil, decl.Type, 0) - b.Field(ctx, ctx.goNodePos(decl), typ, decl.Name, false) + b.Field(ctx, ctx.goNodePos(decl), typ, name, false) case ast.RecordDecl: name, suKind := ctx.getSuName(decl, decl.TagUsed) typ, del := compileStructOrUnion(ctx, name, decl, pub) diff --git a/testdata/libc/src/foo.h b/testdata/libc/src/foo.h index 84ef275..413fab2 100644 --- a/testdata/libc/src/foo.h +++ b/testdata/libc/src/foo.h @@ -9,6 +9,9 @@ typedef struct { struct pub { int a; + int b :1, + :2, + c :3; }; typedef size_t foo_t;