OSDN Git Service

* gcc.dg/c90-const-expr-3.c, gcc.dg/c99-const-expr-3.c: New tests.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / c99-const-expr-3.c
1 /* Test for constant expressions: broken optimization with const variables.  */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=iso9899:1999 -O2" } */
5 /* Note: not using -pedantic since the -std option alone should be enough
6    to give the correct behavior to conforming programs.  */
7
8 static const int ZERO = 0;
9
10 int *a;
11 int b;
12 long *c;
13
14 /* Assertion that n is a constant zero: so the conditional expression
15    has type 'int *' instead of 'void *'.
16 */
17 #define ASSERT_NPC(n)   (b = *(1 ? a : (n)))
18 /* Assertion that n is not a constant zero: so the conditional
19    expresions has type 'void *' instead of 'int *'.
20 */
21 #define ASSERT_NOT_NPC(n)       (c = (1 ? a : (void *)(__SIZE_TYPE__)(n)))
22
23 void
24 foo (void)
25 {
26   ASSERT_NPC (0);
27   ASSERT_NOT_NPC (ZERO);
28   ASSERT_NPC (0 + 0);
29   ASSERT_NOT_NPC (ZERO + 0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
30   ASSERT_NOT_NPC (ZERO + ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
31   ASSERT_NPC (+0);
32   ASSERT_NOT_NPC (+ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
33   ASSERT_NPC (-0);
34   ASSERT_NOT_NPC (-ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
35   ASSERT_NPC ((char) 0);
36   ASSERT_NOT_NPC ((char) ZERO);
37   ASSERT_NPC ((int) 0);
38   ASSERT_NOT_NPC ((int) ZERO);
39 }