aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-04-13 20:15:55 +0200
committerlemon <lsof@mailbox.org>2026-04-13 20:15:55 +0200
commitdc0d3db1f0527b5b50df094bb7ce0f6c9020f60c (patch)
tree400e1c5abab582bb1de15aaa1ca9bcb2abbc18af /src
parent798900fdeb9b7d404572c97cf0adb7b1c09d5096 (diff)
c: implement explicit cast complex -> scalar
Diffstat (limited to 'src')
-rw-r--r--src/c.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/c.c b/src/c.c
index ffe63c0..0ae12d9 100644
--- a/src/c.c
+++ b/src/c.c
@@ -3634,9 +3634,13 @@ compileexpr(Function *fn, const Expr *ex, bool discard)
}
/* fallthru */
case EPLUS:
- r = compileexpr(fn, sub, discard);
- if (discard) return NOREF;
- r = scalarcvt(fn, ex->ty, sub->ty, r);
+ if (!iscomplex(sub->ty) || discard) {
+ r = compileexpr(fn, sub, discard);
+ if (discard) return NOREF;
+ r = scalarcvt(fn, ex->ty, sub->ty, r);
+ } else {
+ r = complex2scalar(fn, ex->ty, sub);
+ }
if (isint(ex->ty) && (typesize(ex->ty) < typesize(sub->ty) || issigned(ex->ty) != issigned(sub->ty)))
return narrow(fn, type2cls[scalartypet(ex->ty)], ex->ty, r, 0);
return r;