1 /* Test for types of conditional expressions. */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
8 (a) The rules are the same in both C standard versions, but C99 also
9 gives us the "restrict" qualifier to play with.
11 (b) Within the C standard, the value of a conditional expression can't
12 have qualified type - but nor can this be detected. Because of GCC's
13 extended lvalues, the value may in GCC have qualified type if the
14 arguments do. So don't use the following macro with arguments of
19 /* Assertion that the type of a conditional expression between E1 and E2
20 is T. Checks the expression both ways round. */
21 #define ASSERT_COND_TYPE(E1, E2, T) \
24 typedef type **typepp; \
25 typedef __typeof(0 ? (E1) : (E2)) ctype; \
26 typedef __typeof(0 ? (E2) : (E1)) ctype2; \
27 typedef ctype **ctypepp; \
28 typedef ctype2 **ctype2pp; \
46 typedef void (*fpt
)(void);
49 struct s
{ int p
; } st
;
50 union u
{ int p
; } un
;
51 /* Arithmetic type. */
52 ASSERT_COND_TYPE (sc
, sc
, int);
53 /* Structure and union. */
54 ASSERT_COND_TYPE (st
, st
, struct s
);
55 ASSERT_COND_TYPE (un
, un
, union u
);
57 ASSERT_COND_TYPE ((void)0, (void)1, void);
58 /* Pointers: examples from 6.5.15 paragraph 8. */
59 ASSERT_COND_TYPE (c_vp
, c_ip
, const void *);
60 ASSERT_COND_TYPE (v_ip
, 0, volatile int *);
61 ASSERT_COND_TYPE (c_ip
, v_ip
, const volatile int *);
62 ASSERT_COND_TYPE (vp
, c_cp
, const void *);
63 ASSERT_COND_TYPE (ip
, c_ip
, const int *);
64 ASSERT_COND_TYPE (vp
, ip
, void *);
65 /* Null pointer constants. */
66 ASSERT_COND_TYPE (v_ip
, (void *)0, volatile int *);
67 ASSERT_COND_TYPE (r_ipp
, (void *)0, int *restrict
*);
68 ASSERT_COND_TYPE (fp
, 0, fpt
);
69 ASSERT_COND_TYPE (fp
, (void *)0, fpt
);