History

enums and ints are compatible

Michael Matz committed 10 years ago

Commit b1a906b1 parent c0368602 files · +10 −0Browse files

Unified · Split

2 files
  1. tccgen.c +8 −0
  2. tests/tcctest.c +2 −0
tccgen.c+8−0
@@ -2565,6 +2565,14 @@ static int compare_types(CType *type1, CType *type2, int unqualified) · 2564 unmodified lines
25652565 t1 &= ~VT_DEFSIGN;
25662566 t2 &= ~VT_DEFSIGN;
25672567 }
2568+ if ((t1 & VT_BTYPE) == VT_ENUM) {
2569+ /* An enum is compatible with (unsigned) int. */
2570+ t1 = VT_INT | (t1 & ~VT_BTYPE);
2571+ }
2572+ if ((t2 & VT_BTYPE) == VT_ENUM) {
2573+ /* An enum is compatible with (unsigned) int. */
2574+ t2 = VT_INT | (t2 & ~VT_BTYPE);
2575+ }
25682576 /* XXX: bitfields ? */
25692577 if (t1 != t2)
25702578 return 0;
tests/tcctest.c+2−0
@@ -590,6 +590,8 @@ enum test { · 589 unmodified lines
590590 void enum_test()
591591 {
592592 enum test b1;
593+ /* The following should give no warning */
594+ int *p = &b1;
593595 printf("enum:\n%d %d %d %d %d %d\n",
594596 E0, E1, E2, E3, E4, E5);
595597 b1 = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t