summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c99-const-expr-5.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-04 23:04:59 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-04 23:04:59 +0000
commit79f925ed078e633914daa2ba9e23b9a827d89264 (patch)
tree57f2351c8ddd1d0c929a34d992db282e82ab724b /gcc/testsuite/gcc.dg/c99-const-expr-5.c
parentc44afe236f0730770ee0bdecddd7da1c5af78568 (diff)
downloadgcc-79f925ed078e633914daa2ba9e23b9a827d89264.tar.gz
* c-typeck.c (null_pointer_constant_p): New function.
(build_conditional_expr, build_c_cast, convert_for_assignment, build_binary_op): Use it. testsuite: * gcc.dg/c90-const-expr-5.c, gcc.dg/c99-const-expr-5.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@108022 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/c99-const-expr-5.c')
-rw-r--r--gcc/testsuite/gcc.dg/c99-const-expr-5.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-5.c b/gcc/testsuite/gcc.dg/c99-const-expr-5.c
new file mode 100644
index 00000000000..e7fdf2c644b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-const-expr-5.c
@@ -0,0 +1,39 @@
+/* Test null pointer constants: typedefs for void should be OK but not
+ qualified void. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+typedef void V;
+int *p;
+long *q;
+int j;
+void (*fp)(void);
+
+void
+f (void)
+{
+ /* (V *)0 is a null pointer constant, so the assignment should be
+ diagnosed. */
+ q = (j ? p : (V *)0); /* { dg-error "error: assignment from incompatible pointer type" } */
+ q = (j ? p : (void *)0); /* { dg-error "error: assignment from incompatible pointer type" } */
+ /* And this conversion should be valid. */
+ (void (*)(void))(V *)0;
+ (void (*)(void))(void *)0;
+ /* Pointers to qualified void are not valid null pointer
+ constants. */
+ fp = (const void *)0; /* { dg-error "error: ISO C forbids assignment between function pointer and 'void \\*'" } */
+ fp = (void *)0;
+ fp = (V *)0;
+ fp = 0;
+ fp == 0;
+ 0 == fp;
+ fp == (void *)0;
+ (void *)0 == fp;
+ fp == (V *)0;
+ (V *)0 == fp;
+ fp == (V *)1; /* { dg-error "error: ISO C forbids comparison of 'void \\*' with function pointer" } */
+ (V *)1 == fp; /* { dg-error "error: ISO C forbids comparison of 'void \\*' with function pointer" } */
+ fp == (const void *)0; /* { dg-error "error: ISO C forbids comparison of 'void \\*' with function pointer" } */
+ (const void *)0 == fp; /* { dg-error "error: ISO C forbids comparison of 'void \\*' with function pointer" } */
+}