This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Further C front end tests


This patch adds more testcases for C front end diagnostics lacking
them.

The tests pass on i686-pc-linux-gnu.  Applied to mainline.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-11-28  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc.dg/builtin-choose-expr-2.c, gcc.dg/cast-1.c,
	gcc.dg/cast-2.c, gcc.dg/cast-3.c, gcc.dg/format/opt-1.c,
	gcc.dg/format/opt-2.c, gcc.dg/format/opt-3.c,
	gcc.dg/format/opt-4.c, gcc.dg/format/opt-5.c,
	gcc.dg/format/opt-6.c, gcc.dg/pointer-arith-5.c,
	gcc.dg/pointer-arith-6.c, gcc.dg/pointer-arith-7.c,
	gcc.dg/pointer-arith-8.c: New tests.

diff -rupN GCC.orig/gcc/testsuite/gcc.dg/builtin-choose-expr-2.c GCC/gcc/testsuite/gcc.dg/builtin-choose-expr-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/builtin-choose-expr-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/builtin-choose-expr-2.c	2004-11-28 00:30:50.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test diagnostic for invalid use of __builtin_choose_expr.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int a, b, c, d;
+
+void
+f (void)
+{
+  a = __builtin_choose_expr (b, c, d); /* { dg-error "error: first argument to '__builtin_choose_expr' not a constant" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/cast-1.c GCC/gcc/testsuite/gcc.dg/cast-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/cast-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/cast-1.c	2004-11-28 01:29:59.000000000 +0000
@@ -0,0 +1,41 @@
+/* Test diagnostics for bad or doubtful casts.  Test with no special
+   options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+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 "error: cast specifies array type" } */
+  (int ()) p; /* { dg-error "error: cast specifies function type" } */
+  (struct s) sv;
+  (union u) uv;
+  (struct s) i; /* { dg-error "error: conversion to non-scalar type requested" } */
+  (union u) i;
+  (union u) l; /* { dg-error "error: cast to union type from type not present in union" } */
+  (int) sv; /* { dg-error "error: aggregate value used where an integer was expected" } */
+  (int) uv; /* { dg-error "error: aggregate value used where an integer was expected" } */
+  (float) sv; /* { dg-error "error: aggregate value used where a float was expected" } */
+  (float) uv; /* { dg-error "error: aggregate value used where a float was expected" } */
+  (_Complex double) sv; /* { dg-error "error: aggregate value used where a complex was expected" } */
+  (_Complex double) uv; /* { dg-error "error: aggregate value used where a complex was expected" } */
+  (void *) sv; /* { dg-error "error: cannot convert to a pointer type" } */
+  (void *) uv; /* { dg-error "error: cannot convert to a pointer type" } */
+  (_Bool) sv; /* { dg-error "error: used struct type value where scalar is required" } */
+  (_Bool) uv; /* { dg-error "error: used union type value where scalar is required" } */
+  (void) sv;
+  (const void) uv;
+  (void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
+  (void *) (char) 1;
+  (char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+  (char) (void *) 1;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/cast-2.c GCC/gcc/testsuite/gcc.dg/cast-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/cast-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/cast-2.c	2004-11-28 01:30:09.000000000 +0000
@@ -0,0 +1,41 @@
+/* Test diagnostics for bad or doubtful casts.  Test with
+   -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic" } */
+
+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 "error: cast specifies array type" } */
+  (int ()) p; /* { dg-error "error: cast specifies function type" } */
+  (struct s) sv; /* { dg-warning "warning: ISO C forbids casting nonscalar to the same type" } */
+  (union u) uv; /* { dg-warning "warning: ISO C forbids casting nonscalar to the same type" } */
+  (struct s) i; /* { dg-error "error: conversion to non-scalar type requested" } */
+  (union u) i; /* { dg-warning "warning: ISO C forbids casts to union type" } */
+  (union u) l; /* { dg-error "error: cast to union type from type not present in union" } */
+  (int) sv; /* { dg-error "error: aggregate value used where an integer was expected" } */
+  (int) uv; /* { dg-error "error: aggregate value used where an integer was expected" } */
+  (float) sv; /* { dg-error "error: aggregate value used where a float was expected" } */
+  (float) uv; /* { dg-error "error: aggregate value used where a float was expected" } */
+  (_Complex double) sv; /* { dg-error "error: aggregate value used where a complex was expected" } */
+  (_Complex double) uv; /* { dg-error "error: aggregate value used where a complex was expected" } */
+  (void *) sv; /* { dg-error "error: cannot convert to a pointer type" } */
+  (void *) uv; /* { dg-error "error: cannot convert to a pointer type" } */
+  (_Bool) sv; /* { dg-error "error: used struct type value where scalar is required" } */
+  (_Bool) uv; /* { dg-error "error: used union type value where scalar is required" } */
+  (void) sv;
+  (const void) uv;
+  (void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
+  (void *) (char) 1;
+  (char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+  (char) (void *) 1;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/cast-3.c GCC/gcc/testsuite/gcc.dg/cast-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/cast-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/cast-3.c	2004-11-28 01:30:19.000000000 +0000
@@ -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 "error: cast specifies array type" } */
+  (int ()) p; /* { dg-error "error: cast specifies function type" } */
+  (struct s) sv; /* { dg-error "error: ISO C forbids casting nonscalar to the same type" } */
+  (union u) uv; /* { dg-error "error: ISO C forbids casting nonscalar to the same type" } */
+  (struct s) i; /* { dg-error "error: conversion to non-scalar type requested" } */
+  (union u) i; /* { dg-error "error: ISO C forbids casts to union type" } */
+  (union u) l; /* { dg-error "error: cast to union type from type not present in union" } */
+  (int) sv; /* { dg-error "error: aggregate value used where an integer was expected" } */
+  (int) uv; /* { dg-error "error: aggregate value used where an integer was expected" } */
+  (float) sv; /* { dg-error "error: aggregate value used where a float was expected" } */
+  (float) uv; /* { dg-error "error: aggregate value used where a float was expected" } */
+  (_Complex double) sv; /* { dg-error "error: aggregate value used where a complex was expected" } */
+  (_Complex double) uv; /* { dg-error "error: aggregate value used where a complex was expected" } */
+  (void *) sv; /* { dg-error "error: cannot convert to a pointer type" } */
+  (void *) uv; /* { dg-error "error: cannot convert to a pointer type" } */
+  (_Bool) sv; /* { dg-error "error: used struct type value where scalar is required" } */
+  (_Bool) uv; /* { dg-error "error: used union type value where scalar is required" } */
+  (void) sv;
+  (const void) uv;
+  (void *) c; /* { dg-warning "warning: cast to pointer from integer of different size" } */
+  (void *) (char) 1;
+  (char) p; /* { dg-warning "warning: cast from pointer to integer of different size" } */
+  (char) (void *) 1;
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/opt-1.c GCC/gcc/testsuite/gcc.dg/format/opt-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/opt-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/opt-1.c	2004-11-28 00:28:13.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostics for options used on their own without
+   -Wformat.  -Wformat-extra-args.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat-extra-args" } */
+
+/* { dg-warning "warning: -Wformat-extra-args ignored without -Wformat" "ignored" { target *-*-* } 0 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/opt-2.c GCC/gcc/testsuite/gcc.dg/format/opt-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/opt-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/opt-2.c	2004-11-28 00:28:13.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostics for options used on their own without
+   -Wformat.  -Wformat-nonliteral.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat-nonliteral" } */
+
+/* { dg-warning "warning: -Wformat-nonliteral ignored without -Wformat" "ignored" { target *-*-* } 0 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/opt-3.c GCC/gcc/testsuite/gcc.dg/format/opt-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/opt-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/opt-3.c	2004-11-28 00:28:13.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostics for options used on their own without
+   -Wformat.  -Wformat-security.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat-security" } */
+
+/* { dg-warning "warning: -Wformat-security ignored without -Wformat" "ignored" { target *-*-* } 0 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/opt-4.c GCC/gcc/testsuite/gcc.dg/format/opt-4.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/opt-4.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/opt-4.c	2004-11-28 00:28:13.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostics for options used on their own without
+   -Wformat.  -Wformat-y2k.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat-y2k" } */
+
+/* { dg-warning "warning: -Wformat-y2k ignored without -Wformat" "ignored" { target *-*-* } 0 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/opt-5.c GCC/gcc/testsuite/gcc.dg/format/opt-5.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/opt-5.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/opt-5.c	2004-11-28 00:28:13.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostics for options used on their own without
+   -Wformat.  -Wformat-zero-length.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat-zero-length" } */
+
+/* { dg-warning "warning: -Wformat-zero-length ignored without -Wformat" "ignored" { target *-*-* } 0 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/opt-6.c GCC/gcc/testsuite/gcc.dg/format/opt-6.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/opt-6.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/opt-6.c	2004-11-28 00:28:13.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostics for options used on their own without
+   -Wformat.  -Wmissing-format-attribute.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-format-attribute" } */
+
+/* { dg-warning "warning: -Wmissing-format-attribute ignored without -Wformat" "ignored" { target *-*-* } 0 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-5.c GCC/gcc/testsuite/gcc.dg/pointer-arith-5.c
--- GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-5.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pointer-arith-5.c	2004-11-28 00:16:04.000000000 +0000
@@ -0,0 +1,17 @@
+/* Test diagnostics for sizeof on void and function types.  Test with
+   no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern const void v;
+void f(void);
+
+void
+g (void)
+{
+  sizeof (v);
+  sizeof (void);
+  sizeof (f);
+  sizeof (void (void));
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-6.c GCC/gcc/testsuite/gcc.dg/pointer-arith-6.c
--- GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-6.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pointer-arith-6.c	2004-11-28 00:17:23.000000000 +0000
@@ -0,0 +1,17 @@
+/* Test diagnostics for sizeof on void and function types.  Test with
+   -Wpointer-arith.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wpointer-arith" } */
+
+extern const void v;
+void f(void);
+
+void
+g (void)
+{
+  sizeof (v); /* { dg-warning "warning: invalid application of 'sizeof' to a void type" } */
+  sizeof (void); /* { dg-warning "warning: invalid application of 'sizeof' to a void type" } */
+  sizeof (f); /* { dg-warning "warning: invalid application of 'sizeof' to a function type" } */
+  sizeof (void (void)); /* { dg-warning "warning: invalid application of 'sizeof' to a function type" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-7.c GCC/gcc/testsuite/gcc.dg/pointer-arith-7.c
--- GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-7.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pointer-arith-7.c	2004-11-28 00:17:51.000000000 +0000
@@ -0,0 +1,17 @@
+/* Test diagnostics for sizeof on void and function types.  Test with
+   -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+extern const void v;
+void f(void);
+
+void
+g (void)
+{
+  sizeof (v); /* { dg-warning "warning: invalid application of 'sizeof' to a void type" } */
+  sizeof (void); /* { dg-warning "warning: invalid application of 'sizeof' to a void type" } */
+  sizeof (f); /* { dg-warning "warning: invalid application of 'sizeof' to a function type" } */
+  sizeof (void (void)); /* { dg-warning "warning: invalid application of 'sizeof' to a function type" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-8.c GCC/gcc/testsuite/gcc.dg/pointer-arith-8.c
--- GCC.orig/gcc/testsuite/gcc.dg/pointer-arith-8.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/pointer-arith-8.c	2004-11-28 00:18:10.000000000 +0000
@@ -0,0 +1,17 @@
+/* Test diagnostics for sizeof on void and function types.  Test with
+   -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+extern const void v;
+void f(void);
+
+void
+g (void)
+{
+  sizeof (v); /* { dg-error "error: invalid application of 'sizeof' to a void type" } */
+  sizeof (void); /* { dg-error "error: invalid application of 'sizeof' to a void type" } */
+  sizeof (f); /* { dg-error "error: invalid application of 'sizeof' to a function type" } */
+  sizeof (void (void)); /* { dg-error "error: invalid application of 'sizeof' to a function type" } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]