please help me submit a bug!

jfondren julian.fondren at gmail.com
Sat Oct 9 05:46:50 UTC 2021


On Saturday, 9 October 2021 at 05:34:28 UTC, workman wrote:
> It take me a lot time to location the bugs:
>
> ```d
> struct T {
>         int     b;
>         ubyte[] a;
> }
>
> enum T A = T(3, [1]);
>
>
> extern(C) int  main(int argc, char** argv) @nogc nothrow {
>         if(argc > 1 &&  A.b ) {
>                 return 0;
>         }
>         return 0;
> }
>
> ```
>
> ```sh
> test.d(7): Error: array literal in `@nogc` function `test.main` 
> may cause a GC allocation
> ```
>
> I am not able to find it because it not throw by a array 
> literal, but by call a enum struct int filed(this struct also 
> include a dynamic array).
>
> In this case I dont get the line number,  and this A.b should 
> be compile time const.

this works:

```d
struct T {
     int b;
     ubyte[] a;
}

// toplevel const implies static
const T A = T(3, [1]);

extern (C) int main(int argc, char** argv) @nogc nothrow {
     if (argc > 1 && A.b) {
         return 0;
     }
     return 0;
}
```

as does this:

```d
extern (C) int main(int argc, char** argv) @nogc nothrow {
     enum Ab = A.b;
     if (argc > 1 && Ab) {
         return 0;
     }
     return 0;
}
```

I don't quite get it, but it looks like your `enum T A` is 
treated like a manifest constant, so it's like you wrote this 
with a runtime construction of the struct and with a GC-allocated 
`[1]`:

```d
extern (C) int main(int argc, char** argv) @nogc nothrow {
     if (argc > 1 && T(3, [1]).b) {
         return 0;
     }
     return 0;
}
```


More information about the Digitalmars-d mailing list