Skip to content

Commit 50c02c9

Browse files
Add failing generic test
1 parent e58de49 commit 50c02c9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

test/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ testrunc99/% : $(SMALL1)/%.c
193193
cd $(SMALL1); ./$*.exe
194194
echo SUCCESS
195195

196+
testrunc11/% : $(SMALL1)/%.c
197+
cd $(SMALL1); $(CILLY) --nomerge --commPrintLn \
198+
$(CFLAGS) -std=c11 $(EXEOUT)$*.exe $*.c -lm
199+
cd $(SMALL1); ./$*.exe
200+
echo SUCCESS
201+
196202
testrungcc/% : $(SMALL1)/%.c mustbegcc
197203
cd $(SMALL1); $(CILLY) --nomerge --commPrintLn \
198204
$(CFLAGS) $(EXEOUT)$*.exe $*.c

test/small1/c11-generic.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "testharness.h"
2+
#define type1(x) _Generic((x), char: 1, unsigned int:2, default:0)
3+
#define type2(x) _Generic((x), char: 1, unsigned int:2, const int:3, default:0)
4+
5+
// This fails to compile but is perfectly legal, since int and const int are not compatible
6+
#define type3(x) _Generic((x), int:1, const int:2, default:0)
7+
8+
int main() {
9+
unsigned char v_uchar;
10+
char v_char;
11+
int v_int;
12+
const int v_intconst;
13+
14+
if(type1(v_int) != 0) { E(1); }
15+
if(type1(v_uchar) != 0) { E(2); }
16+
if(type1(v_char) != 1) { E(3); }
17+
18+
if(type2(v_int) != 0) { E(4); } // This fails but should succeed
19+
if(type2(v_intconst) != 0) { E(5); } // This fails but should succeed
20+
if(type3(v_int) != 1) { E(6); }
21+
if(type3(v_intconst) != 1) { E(7); }
22+
23+
if(type3((const int)v_int) != 1) { E(6); }
24+
if(type3((const int)v_intconst) != 1) { E(7); }
25+
26+
SUCCESS;
27+
}

test/testcil.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ sub addToGroup {
713713
addTest("combinec99inline");
714714
addBadComment("combinec99inline", "C99 inline semantic not fully supported.");
715715

716+
addTest("testrunc11/c11-generic");
716717

717718
# ---------------- c-torture -------------
718719
## if we have the c-torture tests add them

0 commit comments

Comments
 (0)