"Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Apr 8 08:12:22 UTC 2024


On 08/04/2024 10:45 AM, Liam McGillivray wrote:
> On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> Unfortunately runtime and CTFE are the same target in the compiler.
> 
> :-(
> Will this ever be changed?

A tad unlikely, it would be a rather large change architecturally to dmd.

>> ```d
>> template Foo(Args) {
>>     enum Foo = () {
>>         return Args.init;
>>     }();
>> }
>> ```
>>
>> Something like that should work instead.
> 
> I'm sorry, but I can't comprehend any of your example. What would be fed 
> into `Args`? I don't understand how this works, or how I would use it 
> for what I want.

You would replace it with whatever template parameters you want 
(including nothing). It's there as a place holder.

Same for the return on the closure.

But the main thing to understand is that the closure that gives the enum 
a value, that'll be CTFE only, no runtime target.


More information about the Digitalmars-d-learn mailing list