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]

Re: New testcase


On Tue, 14 Nov 2000, Bernd Schmidt wrote:

> char *y = ((char*)&(x[2*8 + 2]) - 8);

This is OK - "an address constant for an object type plus or minus an
integer constant expression".

> int z = (&"Foobar"[1] - &"Foobar"[0]);

Not within ISO C.  (a) The pointers needn't in ISO C point to within the
same object, pointer subtraction is only (6.5.6p9 in C99) defined if they
do; (b) it isn't one of the listed types of constant expressions in
initializers (but maybe 6.6p10 allows such extensions in initializers,
comp.std.c wasn't clear on this when I asked though the view was that the
listed types of integer constant expression couldn't be extended).

OK to commit the following patch?

2000-11-14  Joseph S. Myers  <jsm28@cam.ac.uk>

	* gcc.dg/c90-const-expr-2.c, gcc.dg/c99-const-expr-2.c: Add more
	tests.

--- c90-const-expr-2.c.orig	Tue Aug 15 12:22:42 2000
+++ c90-const-expr-2.c	Tue Nov 14 14:59:45 2000
@@ -31,6 +31,7 @@
   ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   /* This last one is a null pointer constant in C99 only.  */
   ASSERT_NOT_NPC ((void *)(1 ? 0 : (0, 0))); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
 }
--- c99-const-expr-2.c.orig	Tue Aug 15 12:22:42 2000
+++ c99-const-expr-2.c	Tue Nov 14 15:00:42 2000
@@ -31,6 +31,7 @@
   ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   /* This last one is a null pointer constant in C99 only.  */
   ASSERT_NPC ((void *)(1 ? 0 : (0, 0)));
 }

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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