On Wednesday, 17 December 2025 at 14:18:22 UTC, Richard (Rikki) Andrew Cattermole wrote:

On 18/12/2025 3:15 AM, DLearner wrote:
On Wednesday, 17 December 2025 at 00:13:42 UTC, Richard (Rikki) Andrew Cattermole wrote:
[...]
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?

No, this is something that should've been done a while back.

The main concern is that you can get a linker error if you don't emit a function that was called.

Actually, in your example, don't see the problem.
'mixin' operates to provide text to the compiler _prior to_ run time. Therefore, even if 'genStuff()' has a run-time (as well as) compile-time meaning, the use of mixin should force the compile-time meaning to be taken.
So no ambiguity?
DL

genStuff will still compile into the binary.

The error happens when it tries to do that, not when it tries to run it for the string mixin.

And a suitably placed 'if (__ctfe) {...} else {}' within genStuff doesn't help? Idea is to tell the compiler that compilation for execution is entirely redundant.
DL
  • Do string mixins... DLearner via Digitalmars-d-learn
    • Re: Do stri... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Do ... DLearner via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... DLearner via Digitalmars-d-learn
            • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
              • ... DLearner via Digitalmars-d-learn
        • Re:... Adam D. Ruppe via Digitalmars-d-learn
          • ... DLearner via Digitalmars-d-learn
        • Re:... abc via Digitalmars-d-learn
    • Re: Do stri... Kapendev via Digitalmars-d-learn

Reply via email to