]> Cypherpunks repositories - gostls13.git/commitdiff
cgo translates empty function arguments into void instead of dying with 'unexpected...
authorEden Li <eden.li@gmail.com>
Tue, 24 Nov 2009 06:02:12 +0000 (22:02 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 24 Nov 2009 06:02:12 +0000 (22:02 -0800)
  Fixes #162.

R=rsc
https://golang.org/cl/157147

src/cmd/cgo/gcc.go

index 7614f5a3b1969ec768dcb17bc3efd81c9775990b..d2a7eeaddbb4a757757faab15dde9c23cc372112 100644 (file)
@@ -571,6 +571,15 @@ func (c *typeConv) FuncType(dtype *dwarf.FuncType) *FuncType {
        p := make([]*Type, len(dtype.ParamType));
        gp := make([]*ast.Field, len(dtype.ParamType));
        for i, f := range dtype.ParamType {
+               // gcc's DWARF generator outputs a single DotDotDotType parameter for
+               // function pointers that specify no parameters (e.g. void
+               // (*__cgo_0)()).  Treat this special case as void.  This case is
+               // invalid according to ISO C anyway (i.e. void (*__cgo_1)(...) is not
+               // legal).
+               if _, ok := f.(*dwarf.DotDotDotType); ok && i == 0 {
+                       p, gp = nil, nil;
+                       break;
+               }
                p[i] = c.FuncArg(f);
                gp[i] = &ast.Field{Type: p[i].Go};
        }