cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 27e77f6ca6872c8d332c2e153773ca226d69fb64
parent 132e0c466c4198445f8e327c291ab38fe79f6032
Author: Michael Forney <mforney@mforney.org>
Date:   Sun, 17 Feb 2019 17:03:01 -0800

Make enum types compatible with their corresponding integer type (int)

Diffstat:
Atests/compatible-enum-types.c | 3+++
Atests/compatible-enum-types.qbe | 1+
Mtype.c | 4++++
3 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/tests/compatible-enum-types.c b/tests/compatible-enum-types.c @@ -0,0 +1,3 @@ +enum E {A = -1, B}; +enum E x; +int x; diff --git a/tests/compatible-enum-types.qbe b/tests/compatible-enum-types.qbe @@ -0,0 +1 @@ +export data $x = align 4 { z 4 } diff --git a/type.c b/type.c @@ -161,6 +161,10 @@ typecompatible(struct type *t1, struct type *t2) if (t1->kind != t2->kind) return false; switch (t1->kind) { + case TYPEBASIC: + /* enum types are compatible with 'int', but not with + each other (unless they are the same type) */ + return t1->basic.kind == t2->basic.kind && (t1 == &typeint || t2 == &typeint); case TYPEQUALIFIED: if (t1->qualified.kind != t2->qualified.kind) return false;