ORCA-C/Tests/Conformance/C3.5.4.2.CC
Stephen Heumann 91d33b586d Fix various C99+ conformance issues and bugs in test cases.
The main changes made to most tests are:

*Declarations always include explicit types, not relying on implicit int. The declaration of main in most test programs is changed to be "int main (void) {...}", adding an explicit return type and a prototype. (There are still some non-prototyped functions, though.)

*Functions are always declared before use, either by including a header or by providing a declaration for the specific function. The latter approach is usually used for printf, to avoid requiring ORCA/C to process stdio.h when compiling every test case (which might make test runs noticeably slower).

*Make all return statements in non-void functions (e.g. main) return a value.

*Avoid some instances of undefined behavior and type errors in printf and scanf calls.

Several miscellaneous bugs are also fixed.

There are still a couple test cases that intentionally rely on the C89 behavior, to ensure it still works.
2022-10-17 20:17:24 -05:00

164 lines
2.7 KiB
C++

/* Conformance Test 3.5.4.2: Verification of #elif character constant */
/* expressions */
int printf(const char *, ...);
#define FIVE '5'
#define SIX '6'
#if 0
#define NUM1 0
#elif '2' * '8'
#define NUM1 '2' * '8'
#else
#define NUM1 0
#endif
#if 0
#define NUM2 0
#elif '4' / '3'
#define NUM2 '4' / '3'
#else
#define NUM2 0
#endif
#if 0
#define NUM3 0
#elif 'b' - 'a'
#define NUM3 'b' - 'a'
#else
#define NUM3 0
#endif
#if 0
#define NUM4 0
#elif '\r' + '\f'
#define NUM4 '\r' + '\f'
#else
#define NUM4 0
#endif
#if 0
#define NUM5 0
#elif ('p' == '\x70')
#define NUM5 (('\p') == '\x70')
#else
#define NUM5 0
#endif
#if 0
#define NUM6 0
#elif ('\001' != 0)
#define NUM6 ('2'*'8') | ('4'/'3') ^ ('A'-'b')\
& ('\r'+'\f')
#else
#define NUM6 0
#endif
#if 0
#define NUM7 0
#elif ('6' < '7')
#define NUM7 '6' < '7'
#else
#define NUM7 0
#endif
#if 0
#define NUM8 0
#elif ('2' <= '2')
#define NUM8 '2' <= '2'
#else
#define NUM8 0
#endif
#if 0
#define NUM9 0
#elif ('8' > '7')
#define NUM9 '8' > '7'
#else
#define NUM9 0
#endif
#if 0
#define NUM10 0
#elif ('0' >= '0')
#define NUM10 '0' >= '0'
#else
#define NUM10 0
#endif
#if 0
#define NUM11 0
#elif (('\n') && ('\003'))
#define NUM11 (('\n') && ('\003'))
#else
#define NUM11 0
#endif
#if 0
#define NUM12 0
#elif ((0) || ('d'))
#define NUM12 'z' % '0' << '\01' >> '\x2'
#else
#define NUM12 0
#endif
#if 0
#define NUM13 0
#elif -('\x7f')
#define NUM13 (-('\x7f'))
#else
#define NUM13 0
#endif
#if 0
#define NUM14 0
#elif ~('\0')
#define NUM14 ~'\0'
#else
#define NUM14 0
#endif
#if 0
#define NUM15 0
#elif !0
#define NUM15 NUM1 ? NUM2 : 187
#else
#define NUM15 0
#endif
#if 0
#elif (defined(FIVE)) && (defined(SIX)) && (NUM1 == 0xAF0) && (NUM2 == 1)\
&& (NUM3 == NUM2)
int main (void)
{
if (NUM1 != 2800 ) goto Fail;
if (NUM2 != 1 ) goto Fail;
if (NUM3 != 1 ) goto Fail;
if (NUM4 != 25 ) goto Fail;
if (NUM5 != 1 ) goto Fail;
if ((NUM6) != 0xAF8 ) goto Fail;
if (NUM7 != 1 ) goto Fail;
if (NUM8 != 1 ) goto Fail;
if (NUM9 != 1 ) goto Fail;
if (NUM10 != 1 ) goto Fail;
if (NUM11 != 1 ) goto Fail;
if (NUM12 != 13 ) goto Fail;
if (NUM13 != -127 ) goto Fail;
if (NUM14 != -1 ) goto Fail;
if ((NUM15) != 1 ) goto Fail;
printf ("Passed Conformance Test 3.5.4.2\n");
return 0;
Fail:
printf ("Failed Conformance Test 3.5.4.2; location 1\n");
}
#else
int main (void)
{
printf ("Failed Conformance Test 3.5.4.2; location 2\n");
}
#endif