summaryrefslogtreecommitdiffstats
path: root/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c')
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c29
1 files changed, 29 insertions, 0 deletions
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 00000000000..2bc40b2f462
--- /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