summaryrefslogtreecommitdiff
path: root/lib/ccan/cast/test/compile_fail-cast_const.c
blob: 277f3de1c442b21fd9a8953b560a97d5bbb80e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <ccan/cast/cast.h>
#include <stdlib.h>

/* Note: this *isn't* sizeof(char) on all platforms. */
struct char_struct {
	char c;
};

int main(int argc, char *argv[])
{
	char *uc;
	const
#ifdef FAIL
		struct char_struct
#else
		char
#endif
		*p = NULL;

	uc = cast_const(char *, p);
	(void) uc; /* Suppress unused-but-set-variable warning. */
	return 0;
}

#ifdef FAIL
#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
#error "Unfortunately we don't fail if cast_const can only use size"
#endif
#endif