// license that can be found in the LICENSE file.
// Failed to add type conversion for negative constant.
+// Issue 28772: Failed to add type conversion for Go constant set to C constant.
// No runtime test; just make sure it compiles.
package cgotest
/*
#include <complex.h>
+#define issue28772Constant 1
+
static void issue28545F(char **p, int n, complex double a) {}
*/
import "C"
+const issue28772Constant = C.issue28772Constant
+
func issue28545G(p **C.char) {
C.issue28545F(p, -1, (0))
C.issue28545F(p, 2+3, complex(1, 1))
+ C.issue28545F(p, issue28772Constant, (0))
}
f.Package = ast1.Name.Name
f.Name = make(map[string]*Name)
f.NamePos = make(map[*Name]token.Pos)
+ f.Consts = make(map[string]bool)
// In ast1, find the import "C" line and get any extra C preamble.
sawC := false
}
case *ast.CallExpr:
f.saveCall(x, context)
+ case *ast.GenDecl:
+ if x.Tok == token.CONST {
+ for _, spec := range x.Specs {
+ vs := spec.(*ast.ValueSpec)
+ if vs.Type == nil {
+ for _, name := range spec.(*ast.ValueSpec).Names {
+ f.Consts[name.Name] = true
+ }
+ }
+ }
+ }
+
}
}
return x.Name == "nil" ||
strings.HasPrefix(x.Name, "_Ciconst_") ||
strings.HasPrefix(x.Name, "_Cfconst_") ||
- strings.HasPrefix(x.Name, "_Csconst_")
+ strings.HasPrefix(x.Name, "_Csconst_") ||
+ f.Consts[x.Name]
case *ast.UnaryExpr:
return p.isConst(f, x.X)
case *ast.BinaryExpr:
Name map[string]*Name // map from Go name to Name
NamePos map[*Name]token.Pos // map from Name to position of the first reference
Edit *edit.Buffer
+ Consts map[string]bool // untyped constants
}
func (f *File) offset(p token.Pos) int {