Fix type compatiblity of enums and ints

an enum must be compatible with one or more integer type,
so adjust the test accordingly.  That means the following
redeclarations should work:

  enum e6 { E1 = -1, E0 };
  void f3(enum e6);
  void f3(int);        // should work as int and e6 are compatible

while the following should not:

  void f4(enum e6 e);
  void f4(unsigned e); // should error as unsigned and e6 are incompatible
This commit is contained in:
Michael Matz
2020-06-05 16:02:08 +02:00
parent 068d5b3d20
commit 9eef33993a
3 changed files with 41 additions and 29 deletions

View File

@@ -3009,7 +3009,9 @@ static int compare_types(CType *type1, CType *type2, int unqualified)
return (type1->ref == type2->ref);
} else if (bt1 == VT_FUNC) {
return is_compatible_func(type1, type2);
} else if (IS_ENUM(type1->t) || IS_ENUM(type2->t)) {
} else if (IS_ENUM(type1->t) && IS_ENUM(type2->t)) {
/* If both are enums then they must be the same, if only one is then
t1 and t2 must be equal, which was checked above already. */
return type1->ref == type2->ref;
} else {
return 1;