Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / generic.c
blob2fc758543435a0a35c82d285f7985603b1728d6b
1 /*
2 C11 generic associations
3 */
5 #include <testfwk.h>
7 int i;
8 long l;
9 enum {e};
10 typedef char t;
11 t c;
13 void testGeneric(void)
15 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
16 ASSERT (_Generic(i, default : 0, int : 1, long : 2) == 1);
17 ASSERT (_Generic(l, default : 0, int : 1, long int : 2) == 2);
18 ASSERT (_Generic(l, default : 0, int : 1, char : 2) == 0);
19 ASSERT (_Generic('c', default : 0, int : 1, char : 2) == 1);
20 ASSERT (_Generic(7, default : 0, int : 1, char : 2) == 1);
21 ASSERT (_Generic(e, default : 0, int : 1, char : 2) == 1);
22 ASSERT (_Generic(c, default : 0, int : 1, char : 2) == 2);
23 ASSERT (_Generic("c"[0], char : 1, default : 0) == _Generic(c, char : 1, default : 0)); // There once was a bug where the sign of plain char different from the sign of char in string literals.
24 #endif
27 #ifdef __SDCC
28 _Pragma("save")
29 _Pragma("std_c2y") // generic selection with a type name is a C2y feature
30 #endif
32 void testGenericWithType(void)
34 #ifdef __SDCC
35 const int i = 0;
36 ASSERT (_Generic(typeof(i), int : 0, const int : 1, default : 2) == 1);
37 #endif
40 #ifdef __SDCC
41 _Pragma("restore")
42 #endif