func Test30065(t *testing.T) { test30065(t) }
func Test32579(t *testing.T) { test32579(t) }
func Test31891(t *testing.T) { test31891(t) }
+func Test45451(t *testing.T) { test45451(t) }
func TestAlign(t *testing.T) { testAlign(t) }
func TestAtol(t *testing.T) { testAtol(t) }
func TestBlocking(t *testing.T) { testBlocking(t) }
enum Enum40494 { X_40494 };
union Union40494 { int x; };
void issue40494(enum Enum40494 e, union Union40494* up) {}
+
+// Issue 45451, bad handling of go:notinheap types.
+typedef struct issue45451Undefined issue45451;
*/
import "C"
func Issue40494() {
C.issue40494(C.enum_Enum40494(C.X_40494), (*C.union_Union40494)(nil))
}
+
+// Issue 45451.
+func test45451(t *testing.T) {
+ var u *C.issue45451
+ typ := reflect.ValueOf(u).Type().Elem()
+
+ // The type is undefined in C so allocating it should panic.
+ defer func() {
+ if r := recover(); r == nil {
+ t.Error("expected panic")
+ }
+ }()
+
+ _ = reflect.New(typ)
+ t.Errorf("reflect.New(%v) should have panicked", typ)
+}
panic("reflect: New(nil)")
}
t := typ.(*rtype)
+ pt := t.ptrTo()
+ if ifaceIndir(pt) {
+ // This is a pointer to a go:notinheap type.
+ panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)")
+ }
ptr := unsafe_New(t)
fl := flag(Ptr)
- return Value{t.ptrTo(), ptr, fl}
+ return Value{pt, ptr, fl}
}
// NewAt returns a Value representing a pointer to a value of the