diff options
Diffstat (limited to 'lib/ccan/cast/test')
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_const.c | 29 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_const2.c | 29 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_const3.c | 29 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_signed-const.c | 22 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c | 29 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_signed.c | 17 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_static-2.c | 23 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_static-3.c | 21 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_fail-cast_static.c | 17 | ||||
-rw-r--r-- | lib/ccan/cast/test/compile_ok-cast_void.c | 12 |
10 files changed, 228 insertions, 0 deletions
diff --git a/lib/ccan/cast/test/compile_fail-cast_const.c b/lib/ccan/cast/test/compile_fail-cast_const.c new file mode 100644 index 0000000000..277f3de1c4 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_const.c @@ -0,0 +1,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 diff --git a/lib/ccan/cast/test/compile_fail-cast_const2.c b/lib/ccan/cast/test/compile_fail-cast_const2.c new file mode 100644 index 0000000000..e671e88eda --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_const2.c @@ -0,0 +1,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_const2(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 diff --git a/lib/ccan/cast/test/compile_fail-cast_const3.c b/lib/ccan/cast/test/compile_fail-cast_const3.c new file mode 100644 index 0000000000..e958e2dde5 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_const3.c @@ -0,0 +1,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_const3(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 diff --git a/lib/ccan/cast/test/compile_fail-cast_signed-const.c b/lib/ccan/cast/test/compile_fail-cast_signed-const.c new file mode 100644 index 0000000000..9971dc8eb3 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_signed-const.c @@ -0,0 +1,22 @@ +#include <ccan/cast/cast.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + unsigned char *uc; +#ifdef FAIL + const +#endif + char + *p = NULL; + + uc = cast_signed(unsigned 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 diff --git a/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c b/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c new file mode 100644 index 0000000000..2bc40b2f46 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c @@ -0,0 +1,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[]) +{ + unsigned char *uc; +#ifdef FAIL + struct char_struct +#else + char +#endif + *p = NULL; + + uc = cast_signed(unsigned 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_signed can only use size" +#endif +#endif diff --git a/lib/ccan/cast/test/compile_fail-cast_signed.c b/lib/ccan/cast/test/compile_fail-cast_signed.c new file mode 100644 index 0000000000..66bcc0a1b5 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_signed.c @@ -0,0 +1,17 @@ +#include <ccan/cast/cast.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + unsigned char *uc; +#ifdef FAIL + int +#else + char +#endif + *p = NULL; + + uc = cast_signed(unsigned char *, p); + (void) uc; /* Suppress unused-but-set-variable warning. */ + return 0; +} diff --git a/lib/ccan/cast/test/compile_fail-cast_static-2.c b/lib/ccan/cast/test/compile_fail-cast_static-2.c new file mode 100644 index 0000000000..8a12025384 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_static-2.c @@ -0,0 +1,23 @@ +#include <ccan/cast/cast.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + char *c; +#ifdef FAIL + long +#else + char +#endif + *p = 0; + + c = cast_static(char *, p); + (void) c; /* Suppress unused-but-set-variable warning. */ + return 0; +} + +#ifdef FAIL +#if !HAVE_COMPOUND_LITERALS +#error "Unfortunately we don't fail if cast_static is a noop" +#endif +#endif diff --git a/lib/ccan/cast/test/compile_fail-cast_static-3.c b/lib/ccan/cast/test/compile_fail-cast_static-3.c new file mode 100644 index 0000000000..6296b75276 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_static-3.c @@ -0,0 +1,21 @@ +#include <ccan/cast/cast.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + char *c; +#ifdef FAIL + const +#endif + char *p = 0; + + c = cast_static(char *, p); + (void) c; /* Suppress unused-but-set-variable warning. */ + return 0; +} + +#ifdef FAIL +#if !HAVE_COMPOUND_LITERALS +#error "Unfortunately we don't fail if cast_static is a noop" +#endif +#endif diff --git a/lib/ccan/cast/test/compile_fail-cast_static.c b/lib/ccan/cast/test/compile_fail-cast_static.c new file mode 100644 index 0000000000..0f9e478047 --- /dev/null +++ b/lib/ccan/cast/test/compile_fail-cast_static.c @@ -0,0 +1,17 @@ +#include <ccan/cast/cast.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + char c; +#ifdef FAIL + char * +#else + long +#endif + x = 0; + + c = cast_static(char, x); + (void) c; /* Suppress unused-but-set-variable warning. */ + return 0; +} diff --git a/lib/ccan/cast/test/compile_ok-cast_void.c b/lib/ccan/cast/test/compile_ok-cast_void.c new file mode 100644 index 0000000000..c649d283b3 --- /dev/null +++ b/lib/ccan/cast/test/compile_ok-cast_void.c @@ -0,0 +1,12 @@ +#include <ccan/cast/cast.h> + +static void *remove_void(const void *p) +{ + return cast_const(void *, p); +} + +int main(void) +{ + void *p = remove_void("foo"); + return !p; +} |