aboutsummaryrefslogtreecommitdiff
path: root/type.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2020-06-03 03:22:11 -0700
committerMichael Forney <mforney@mforney.org>2020-06-03 03:22:11 -0700
commit38b1d570ac9f35af9b58e7ff33d61698b83384ff (patch)
tree2a8a03923d5e786205658fdae923f77ce4c8b835 /type.c
parent662a5dd71ed37fd8938f0da4f64149bcf07ba154 (diff)
Revert "decl: Allow out-of-range enum constants when they don't change type"
This reverts commit 6229709b8ae21d7722fef48ad8a9f2f10b900030. I still don't understand how out-of-range enum constants are supposed to work.
Diffstat (limited to 'type.c')
-rw-r--r--type.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/type.c b/type.c
index 14ac033..87f8094 100644
--- a/type.c
+++ b/type.c
@@ -106,6 +106,7 @@ typerank(struct type *t)
case TYPEBOOL: return 1;
case TYPECHAR: return 2;
case TYPESHORT: return 3;
+ case TYPEENUM:
case TYPEINT: return 4;
case TYPELONG: return 5;
case TYPELLONG: return 6;
@@ -122,16 +123,14 @@ typecompatible(struct type *t1, struct type *t2)
if (t1 == t2)
return true;
- if (t1->kind != t2->kind)
- return false;
- switch (t1->kind) {
- case TYPEINT:
- case TYPELONG:
- case TYPELLONG:
- /* enum types are compatible with some basic integer
- type, but not with other enum types */
- return (t1->prop & PROPENUM) != (t2->prop & PROPENUM) &&
+ if (t1->kind != t2->kind) {
+ /* enum types are compatible with 'int', but not with
+ each other (unless they are the same type) */
+ return (t1->kind == TYPEENUM && t2->kind == TYPEINT ||
+ t1->kind == TYPEINT && t2->kind == TYPEENUM) &&
t1->basic.issigned == t2->basic.issigned;
+ }
+ switch (t1->kind) {
case TYPEPOINTER:
goto derived;
case TYPEARRAY: