www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - need solution for find error : Error: `TypeInfo` cannot be used with

reply test123 <test123 gmail.com> writes:
some time a huge project build throw error: "Error: `TypeInfo` 
cannot be used with -betterC"

and it work before some days ago, there is no array allow but 
throw this error.  no location information (file and line).


We need solution to improve the error message so people can find 
where to fix it.
Jul 21 2022
next sibling parent test123 <test123 gmail.com> writes:
On Friday, 22 July 2022 at 06:06:09 UTC, test123 wrote:
 some time a huge project build throw error: "Error: `TypeInfo` 
 cannot be used with -betterC"

 and it work before some days ago, there is no array allow but 
 throw this error.  no location information (file and line).


 We need solution to improve the error message so people can 
 find where to fix it.
"ldc2/bin/../import/std/array.d(1116): Error: `TypeInfo` cannot be used with -betterC",
Jul 21 2022
prev sibling parent reply test123 <test123 gmail.com> writes:
On Friday, 22 July 2022 at 06:06:09 UTC, test123 wrote:
 some time a huge project build throw error: "Error: `TypeInfo` 
 cannot be used with -betterC"

 and it work before some days ago, there is no array allow but 
 throw this error.  no location information (file and line).


 We need solution to improve the error message so people can 
 find where to fix it.
not my first time find this problem. but this time is not make no sense. ```d import std.bitmanip : bitfields; enum UserRole : ubyte { None = 0, } alias UserIdT = ushort; enum BIT_COUNT = 30; enum MAX_COUNT = 2 ^^ BIT_COUNT; struct UserSession { union { ulong uint64; mixin(bitfields!( UserIdT, "user_id", 16, UserRole, "user_role", 2, uint, "login_count", BIT_COUNT, )); } } extern(C) void main(){ } ``` there is no array related code, but throw TypeInfo error
Jul 21 2022
next sibling parent Paul Backus <snarwin gmail.com> writes:
On Friday, 22 July 2022 at 06:16:56 UTC, test123 wrote:
 there is no array related code, but throw TypeInfo error
`bitfields` probably uses an array in CTFE somewhere. Due to limitations of the current compiler, BetterC code is not allowed to use arrays even in code that is only executed at compile time (bug report: https://issues.dlang.org/show_bug.cgi?id=19268).
Jul 22 2022
prev sibling parent reply user1234 <user1234 12.de> writes:
On Friday, 22 July 2022 at 06:16:56 UTC, test123 wrote:
 On Friday, 22 July 2022 at 06:06:09 UTC, test123 wrote:
 some time a huge project build throw error: "Error: `TypeInfo` 
 cannot be used with -betterC"

 and it work before some days ago, there is no array allow but 
 throw this error.  no location information (file and line).
[...] there is no array related code, but throw TypeInfo error
your bitfield size is not good, which leads to a `to!string` in a `static assert` that uses array under the hood. With a good size, ```d struct UserSession { union { ulong uint64; mixin(bitfields!( UserIdT, "user_id", 16, UserRole, "user_role", 2, uint, "login_count", BIT_COUNT, uint, "pad", 16 )); } } ``` there's another error in `myToString()`
 Error: array concatenation of expression `cast(const(char)[])s 
 ~ (n > 4294967295LU ? "UL" : "U")` requires the GC which is not 
 available with -betterC
what's unfair is that both problems are caused by static evaluation/CTFE. That's compiler bugs. The compiler thinks that the code will be used at run-time while it is only statically evaluated, hence there's no betterC restrictions. For `myToString()`, maybe also that `pragma(ctfe)` would be required. I see no solution excepted the one that is to write a simpler, stripped down, version of `bitfields`.
Jul 22 2022
parent ryuukk_ <ryuukk.dev gmail.com> writes:
Alternatively you can grab latest DMD night and use builtin 
bitfield feature


`-preview=bitfields`

https://dlang.org/changelog/pending.html#bitfields
Jul 22 2022