Do string mixins work under -betterC?
DLearner
bmqazwsx123 at gmail.com
Tue Dec 16 23:25:18 UTC 2025
On Tuesday, 16 December 2025 at 20:56:06 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> On 17/12/2025 9:48 AM, DLearner wrote:
>> I have a rather complicated string mixin defined and invoked
>> from within the same source file.
>> Which seems to work.
>>
>> But when I move the mixin definition to a separate module, and
>> import that module into the original source file, the
>> compilation collapses complaining that array concatenation
>> requires the GC, which is not available with -betterC.
>>
[...]
> string genStuff(string val) {
> return val ~ ";";
> }
>
> void myFunc() {
> mixin(genStuff("this"));
> }
> ```
>
> This won't work without a way to mark `genStuff` as CTFE only.
> Which doesn't exist currently.
>
> Compiler has to know that a given execution context is CTFE
> only otherwise disallowed.
1. Any proposals to mark a function as CTFE only?
2. Why (and I've now got this down to a cut-and-paste) is there
no problem if the mixin definition is in the main function, but
problem appears if the definition is moved to a separate module
(which is imported into the main function)?
DL
More information about the Digitalmars-d-learn
mailing list