1// Copyright 2016 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5// Issue 17537. The void* cast introduced by cgo to avoid problems 6// with const/volatile qualifiers breaks C preprocessor macros that 7// emulate functions. 8 9package cgotest 10 11/* 12#include <stdlib.h> 13 14typedef struct { 15 int i; 16} S17537; 17 18int I17537(S17537 *p); 19 20#define I17537(p) ((p)->i) 21 22// Calling this function used to fail without the cast. 23const int F17537(const char **p) { 24 return **p; 25} 26 27// Calling this function used to trigger an error from the C compiler 28// (issue 18298). 29void F18298(const void *const *p) { 30} 31 32// Test that conversions between typedefs work as they used to. 33typedef const void *T18298_1; 34struct S18298 { int i; }; 35typedef const struct S18298 *T18298_2; 36void G18298(T18298_1 t) { 37} 38*/ 39import "C" 40 41import "testing" 42 43func test17537(t *testing.T) { 44 v := C.S17537{i: 17537} 45 if got, want := C.I17537(&v), C.int(17537); got != want { 46 t.Errorf("got %d, want %d", got, want) 47 } 48 49 p := (*C.char)(C.malloc(1)) 50 *p = 17 51 if got, want := C.F17537(&p), C.int(17); got != want { 52 t.Errorf("got %d, want %d", got, want) 53 } 54 55 C.F18298(nil) 56 var v18298 C.T18298_2 57 C.G18298(C.T18298_1(v18298)) 58} 59