ORCA-C/Tests/Deviance/D7.8.0.1.CC
Stephen Heumann 102d6873a3 Fix type checking and result type computation for ? : operator.
This was non-standard in various ways, mainly in regard to pointer types. It has been rewritten to closely follow the specification in the C standards.

Several helper functions dealing with types have been introduced. They are currently only used for ? :, but they might also be useful for other purposes.

New tests are also introduced to check the behavior for the ? : operator.

This fixes #35 (including the initializer-specific case).
2022-06-23 22:05:34 -05:00

28 lines
734 B
C++

/* Deviance Test 7.8.0.1: Ensure invalid operand types for ?: are detected */
int printf(const char *, ...);
int main(void) {
int i = 1;
struct S {int i;} s = {4};
int *ip = &i;
long *lp = 0;
const int *cip = &i;
/* each statement below should give an error */
1 ? i : s;
1 ? s : i;
1 ? i : (void)0;
1 ? ip : lp;
/* these are illegal in standard C, but allowed by loose type checks */
#pragma ignore 24
1 ? main : (void*)(void*)0;
1 ? &ip : &cip;
/* should give an error, but currently does not in ORCA/C */
1 ? cip : (char)+0.0;
printf ("Failed Deviance Test 7.8.0.1\n");
}