@ctfeonly
Walter Bright
newshound2 at digitalmars.com
Fri Dec 8 03:41:05 UTC 2017
On 12/7/2017 3:41 PM, Nicholas Wilson wrote:
> On Thursday, 7 December 2017 at 21:32:24 UTC, Walter Bright wrote:
>> On 12/7/2017 2:07 AM, Nicholas Wilson wrote:
>>> Doesn't work for templates.
>>
>> I don't know how your code is organized, but if the template is instantiated
>> in another file, it won't have code generated for it either.
>
> As a trivial example:
>
> bar.d:
> module bar;
> string generatesMixin(T)()
> {
> return T.stringof ~ " foo;";
> }
>
>
> a.d:
> @compute(CompileFor.deviceOnly) module a;
>
> int baz()
> {
> mixin(generatesMixin!int());
> return foo;
> }
>
> a's symbol table contains `baz` and `generatesMixin!int`. generateMixin deals
> with strings which are not allowed (global variables are unsupported). This
> would fail compilation. If `generatesMixin` were to be marked `@ctfeonly`, this
> would pass.
>
bar.d:
module bar;
string generateString(T)()
{
return T.stringof ~ " foo;";
}
enum s = generateString!int();
a.d:
@compute(CompileFor.deviceOnly) module a;
int baz()
{
import bar;
bar.s;
return foo;
}
More information about the Digitalmars-d
mailing list