1 /* Test for constant expressions: details of what is a null pointer 2 constant. 3 */ 4 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ 5 /* { dg-do compile } */ 6 /* { dg-options "-std=iso9899:1999" } */ 7 /* Note: not using -pedantic since the -std option alone should be enough 8 to give the correct behavior to conforming programs. If -pedantic is 9 needed to make (say) (0, 0) not be a constant expression, this is a 10 bug. 11 */ 12 13 int *a; 14 int b; 15 long *c; 16 17 /* Assertion that n is a null pointer constant: so the conditional expression 18 has type 'int *' instead of 'void *'. 19 */ 20 #define ASSERT_NPC(n) (b = *(1 ? a : (n))) 21 /* Assertion that n is not a null pointer constant: so the conditional 22 expresions has type 'void *' instead of 'int *'. 23 */ 24 #define ASSERT_NOT_NPC(n) (c = (1 ? a : (n))) 25 26 void 27 foo (void) 28 { 29 ASSERT_NPC (0); 30 ASSERT_NPC ((void *)0); 31 ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */ 32 ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */ 33 ASSERT_NOT_NPC ((void *)(0, 0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */ 34 ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */ 35 /* This last one is a null pointer constant in C99 only. */ 36 ASSERT_NPC ((void *)(1 ? 0 : (0, 0))); 37 } 38