From 98ffc031d16efe00b4338e79f903382aa54af957 Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 9 Dec 2023 14:35:00 +0800 Subject: [PATCH] Fixed an iteration bug in type composition. --- src/cc65/expr.c | 3 ++- src/cc65/typeconv.c | 7 ------- test/err/bug2285-composite-type.c | 5 +++++ 3 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 test/err/bug2285-composite-type.c diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 54984230c..a87335f42 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -4102,9 +4102,10 @@ static void hieQuest (ExprDesc* Expr) /* Avoid further errors */ ResultType = NewPointerTo (type_void); } else { - /* Result has the composite type */ + /* Result has the properly qualified composite type */ ResultType = TypeDup (Expr2.Type); TypeComposition (ResultType, Expr3.Type); + ResultType[1].C |= GetQualifier (Indirect (Expr3.Type)); } } } else if (IsClassPtr (Expr2.Type) && Expr3IsNULL) { diff --git a/src/cc65/typeconv.c b/src/cc65/typeconv.c index e5b054148..e5b6749d6 100644 --- a/src/cc65/typeconv.c +++ b/src/cc65/typeconv.c @@ -485,13 +485,6 @@ void TypeComposition (Type* lhs, const Type* rhs) } else if (RightCount != UNSPECIFIED) { SetElementCount (lhs, RightCount); } - } else { - /* Combine the qualifiers */ - if (IsClassPtr (lhs)) { - ++lhs; - ++rhs; - lhs->C |= GetQualifier (rhs); - } } /* Next type string element */ diff --git a/test/err/bug2285-composite-type.c b/test/err/bug2285-composite-type.c new file mode 100644 index 000000000..18a7b80a5 --- /dev/null +++ b/test/err/bug2285-composite-type.c @@ -0,0 +1,5 @@ +/* Bug #2285 - Regression in type composition */ + +void foo(); /* OK */ +void foo(int (*)(int)); /* OK */ +void foo(int (*)(long)); /* WRONG: Should be an error */