Bug 24398 – CTFE evaluation of iota() fails inside extern(C++) struct

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2024-02-18T08:49:58Z
Last change time
2024-12-13T19:33:23Z
Assigned to
No Owner
Creator
Gregor Mückl
Moved to GitHub: dmd#20404 →

Comments

Comment #0 by gregormueckl — 2024-02-18T08:49:58Z
The following code used to compile with DMD versions between 2.086.1 to 2.100.2, but starting from DMD 2.102 it fails. I haven't bisected it further, but I assume this is a bug: ``` extern(C++) struct X { static foreach(i; iota(0, 3)) { } } ``` Compilation fails with the message: ``` onlineapp.d(5): Error: function `onlineapp.X.__lambda2` cannot return type `int[]` because its linkage is `extern(C++)` onlineapp.d(5): slices are specific to D and do not have a counterpart representation in C++ ``` I'm using patterns like this to generate a lot of struct members that follow simple patterns using mixins. I assume that the cause of the error is that the iota() is rejected based on the extern(C++) for the context, even though the evaluation is strictly CTFE due to the static foreach.
Comment #1 by robert.schadek — 2024-12-13T19:33:23Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20404 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB