summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/cast-3.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/cast-3.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/cast-3.c')
-rw-r--r--gcc/testsuite/gcc.dg/cast-3.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cast-3.c b/gcc/testsuite/gcc.dg/cast-3.c
new file mode 100644
index 000000000..40d3c88c6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cast-3.c
@@ -0,0 +1,41 @@
+/* Test diagnostics for bad or doubtful casts. Test with
+ -pedantic-errors. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+struct s { int a; } sv;
+union u { int a; } uv;
+int i;
+long l;
+char c;
+void *p;
+float fv;
+
+void
+f (void)
+{
+ (int []) p; /* { dg-error "cast specifies array type" } */
+ (int ()) p; /* { dg-error "cast specifies function type" } */
+ (struct s) sv; /* { dg-error "ISO C forbids casting nonscalar to the same type" } */
+ (union u) uv; /* { dg-error "ISO C forbids casting nonscalar to the same type" } */
+ (struct s) i; /* { dg-error "conversion to non-scalar type requested" } */
+ (union u) i; /* { dg-error "ISO C forbids casts to union type" } */
+ (union u) l; /* { dg-error "cast to union type from type not present in union" } */
+ (int) sv; /* { dg-error "aggregate value used where an integer was expected" } */
+ (int) uv; /* { dg-error "aggregate value used where an integer was expected" } */
+ (float) sv; /* { dg-error "aggregate value used where a float was expected" } */
+ (float) uv; /* { dg-error "aggregate value used where a float was expected" } */
+ (_Complex double) sv; /* { dg-error "aggregate value used where a complex was expected" } */
+ (_Complex double) uv; /* { dg-error "aggregate value used where a complex was expected" } */
+ (void *) sv; /* { dg-error "cannot convert to a pointer type" } */
+ (void *) uv; /* { dg-error "cannot convert to a pointer type" } */
+ (_Bool) sv; /* { dg-error "used struct type value where scalar is required" } */
+ (_Bool) uv; /* { dg-error "used union type value where scalar is required" } */
+ (void) sv;
+ (const void) uv;
+ (void *) c; /* { dg-warning "cast to pointer from integer of different size" } */
+ (void *) (char) 1;
+ (char) p; /* { dg-warning "cast from pointer to integer of different size" } */
+ (char) (void *) 1; /* { dg-warning "cast from pointer to integer of different size" } */
+}