Request for Comment assert(__ctfe)

Johannes Pfau nospam at example.com
Tue Apr 7 16:53:19 UTC 2020


Am Tue, 07 Apr 2020 12:09:48 +0000 schrieb Stefan Koch:

> On Tuesday, 7 April 2020 at 11:32:27 UTC, Johannes Pfau wrote:
>>
>> And the most important thing: This will vastly improve betterC / nogc
>> code:
>>
>> --------------------
>> string generateMixin(T)(string b)
>> {
>>     assert(__ctfe);
>>     return T.stringof ~ " " ~ b ~ ";";
>> }
>>
>> void main() @nogc {
>>     mixin(generateMixin!string("b"));
>> }
>> --------------------
> 
> 
> I can confirm with the patch there are no template-instances in the
> object file

The example above actually already compiles with -betterC, as the check 
is done in codegen phase! But some betterC checks seem to be done in 
semantic. This doesn't work yet:

------------------------
string generateMixin(T)(string b)
{
    assert(__ctfe);
    return typeid(T).stringof ~ " " ~ b ~ ";";
}

void main() @nogc
{
    mixin(generateMixin!string("b"));
}
------------------------
dmd -betterC test.d -c
test.d(4): Error: TypeInfo cannot be used with -betterC


-- 
Johannes


More information about the Digitalmars-d mailing list