Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.dg / c90-const-expr-2.c
blobcad5bc8673b5da0f0cf6844b55d5445a3f1b56a5
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:1990" } */
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.
13 int *a;
14 int b;
15 long *c;
17 #if defined(_LP64) || defined(_WIN64)
18 #define ZERO 0L
19 #else
20 #define ZERO 0
21 #endif
23 /* Assertion that n is a null pointer constant: so the conditional expression
24 has type 'int *' instead of 'void *'.
26 #define ASSERT_NPC(n) (b = *(1 ? a : (n)))
27 /* Assertion that n is not a null pointer constant: so the conditional
28 expressions has type 'void *' instead of 'int *'.
30 #define ASSERT_NOT_NPC(n) (c = (1 ? a : (n)))
32 void
33 foo (void)
35 ASSERT_NPC (0);
36 ASSERT_NPC ((void *)0);
37 ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
38 ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
39 ASSERT_NOT_NPC ((void *)(0, ZERO)); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
40 ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
41 /* This last one is a null pointer constant in C99 only. */
42 ASSERT_NOT_NPC ((void *)(1 ? 0 : (0, 0))); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */