← Back to index
|
Original Bugzilla link
Bug 12576 – problem with compile time struct field
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-04-13T21:47:06Z
Last change time
2020-07-08T11:07:39Z
Assigned to
No Owner
Creator
Ellery Newcomer
Comments
Comment #0
by ellery-newcomer — 2014-04-13T21:47:06Z
the code: template Replace(string base, T...) { template NextAt(string base, string longest_spec, size_t _at0, T...) { } NextAt!(base,"",-1,T) N; } struct _CppFunction { string funcname; } string CppClass1(string name, Clazz)() { enum _CppFunction cf = { }; enum mix = Replace!(" ReturnType Func(Params) { return Mangled(args); }\n", "Func", cf.funcname); return mix; } enum Mixins = CppClass1!("X", typeof(new class { })); the fireworks: $ dmd error1 error1.d(9): Error: template instance NextAt!("\x0a ReturnType Func(Params) {\x0a return Mangled(args);\x0a }\x0a", "", -1, "Func", funcname) cannot use local 'funcname' as parameter to non-global template NextAt(string base, string longest_spec, ulong _at0, T...) error1.d(20): Error: template instance error1._CppFunction.Replace!("\x0a ReturnType Func(Params) {\x0a return Mangled(args);\x0a }\x0a", "Func", funcname) error instantiating error1.d(28): instantiated from here: CppClass1!("X", __anonclass1)
Comment #1
by k.hara.pg — 2014-04-21T04:33:02Z
Is this a possible workaround for your 'original' code? I'm not sure it's the actual issue, because the code still fail to compile. template Replace(string base, T...) { template NextAt(string base, string longest_spec, size_t _at0, T...) { } NextAt!(base,"",-1,T) N; } struct _CppFunction { string funcname; } string CppClass1(string name, Clazz)() { enum _CppFunction cf = { }; enum x = cf.funcname; // <--- workaround? enum mix = Replace!(" ReturnType Func(Params) { return Mangled(args); }\n", "Func", /*cf.funcname*/x); // <--- workaround? return mix; } enum Mixins = CppClass1!("X", typeof(new class { }));
Comment #2
by ellery-newcomer — 2014-04-22T01:26:04Z
yeah, that's what I do now, so this one is probably not the highest priority
Comment #3
by simen.kjaras — 2020-07-08T11:07:39Z
While the code in these examples don't compile today, that appears to be because it's incomplete. The underlying issue 5710 has been fixed.