[Issue 24398] New: CTFE evaluation of iota() fails inside extern(C++) struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 18 08:49:58 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24398

          Issue ID: 24398
           Summary: CTFE evaluation of iota() fails inside extern(C++)
                    struct
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: gregormueckl at gmx.de

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.

--


More information about the Digitalmars-d-bugs mailing list