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