pragma(__ctfe)

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Sep 28 17:15:45 UTC 2023


On 29/09/2023 6:08 AM, Steven Schveighoffer wrote:
> On 9/28/23 4:02 AM, Richard (Rikki) Andrew Cattermole wrote:
>> On 28/09/2023 8:36 PM, Nicholas Wilson wrote:
>>> It will screw up .di generation, and make separate compilation more 
>>> difficult.
>>
>> No not really, think about the constraints of CTFE.
>>
>> You can't elide a function body which is to be used from CTFE. Since 
>> you have to have the function body to CTFE it.
>>
>> So where the annotation exists, doesn't matter too much.
> 
> I think what Nic means is if you have a function:
> 
> ```d
> string genMixin(string param) {
>     assert(__ctfe);
>     return "int " ~ param ~ " = 5;";
> }
> ```
> 
> Now, if that doesn't go into the binary, what happens with the di 
> generated file?
> 
> ```d
> string genMixin(string param);
> ```
> 
> oops, there's the function, but it can't be called for CTFE, *and* it 
> doesn't exist in the object file.
> 
> Personally, I don't see the problem here. Don't use .di files generation 
> for d files that contain those functions.
> 
> Or the compiler can detect it, and omit the function, but meh.
> 
> -Steve

Yeah, I got it. Don't elide the function body of a CTFE only function, 
or one called from it and it will work fine, which is what I said :)


More information about the Digitalmars-d mailing list