www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - unclear compile error for struct with string template

reply "Oleg B" <antidote32 mail.ru> writes:
[code]
void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
struct vec(size_t N, T, string AS) { T[N] data; }
void main() { doSome( vec!(3,float,"xyz")([1,2,3]) ); }
[/code]

compile with new dmd v2.066.0 and get error:

Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
AS) v) specialization not allowed for deduced parameter AS

what does it mean?

on dmd v2.065 it worked well

code without string template parameter work well on dmd v2.066.0

[code]
void doSome(size_t N, T)( vec!(N,T) v ) { }
struct vec(size_t N, T) { T[N] data; }
void main() { doSome( vec!(3,float)([1,2,3]) ); }
[/code]
Aug 25 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Oleg B:

 [code]
 void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
 struct vec(size_t N, T, string AS) { T[N] data; }
 void main() { doSome( vec!(3,float,"xyz")([1,2,3]) ); }
 [/code]

 compile with new dmd v2.066.0 and get error:

 Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
 AS) v) specialization not allowed for deduced parameter AS

 what does it mean?
See also: struct Vec(size_t N, T, alias string AS) { T[N] data; } void doSome(size_t N, T, alias string AS)(Vec!(N, T, AS) v) {} void main() { auto v = Vec!(3, float, "xyz")([1, 2, 3]); doSome(v); } (Note that in D the names of types and structs start with an upper case). Bye, bearophile
Aug 25 2014
parent reply "Oleg B" <antidote32 mail.ru> writes:
On Monday, 25 August 2014 at 11:41:28 UTC, bearophile wrote:
 Oleg B:

 [code]
 void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
 struct vec(size_t N, T, string AS) { T[N] data; }
 void main() { doSome( vec!(3,float,"xyz")([1,2,3]) ); }
 [/code]

 compile with new dmd v2.066.0 and get error:

 Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
 AS) v) specialization not allowed for deduced parameter AS

 what does it mean?
See also: struct Vec(size_t N, T, alias string AS) { T[N] data; } void doSome(size_t N, T, alias string AS)(Vec!(N, T, AS) v) {} void main() { auto v = Vec!(3, float, "xyz")([1, 2, 3]); doSome(v); } (Note that in D the names of types and structs start with an upper case). Bye, bearophile
Does it mean that I need write "alias" for all arrays in template parameters or only strings?
Aug 25 2014
parent "Oleg B" <antidote32 mail.ru> writes:
and when I minimal fix my libs with this issue compiler fails 
without any output... =(

% gdb dmd
(gdb) run -unittest matrix.d vector.d
Starting program: /usr/bin/dmd -unittest matrix.d vector.d
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff7ec9700 (LWP 29224)]
[Thread 0x7ffff7ec9700 (LWP 29224) exited]

Program received signal SIGSEGV, Segmentation fault.
0x000000000046c39a in ctfeInterpret(Expression*) ()
(gdb) bt


Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, 
unsigned long)::DeduceType::visit(TypeInstance*) ()

Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, 
unsigned long) ()

Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, 
unsigned long)::DeduceType::visit(TypeStruct*) ()

Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, 
unsigned long)::DeduceType::visit(Expression*) ()

Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, 
unsigned long) ()

TemplateDeclaration::deduceFunctionTemplateMatch(TemplateInstance*, 
Scope*, FuncDeclaration*&, Type*, Array<Expression*>*) ()

Scope*, Array<RootObject*>*, Type*, 
Array<Expression*>*)::ParamDeduce::fp(void*, Dsymbol*) ()

(*)(void*, Dsymbol*)) ()

Scope*, Array<RootObject*>*, Type*, Array<Expression*>*) ()

Array<RootObject*>*, Type*, Array<Expression*>*, int) ()










<main>, argc=4, ubp_av=0x7fffffffdc28, init=<optimized out>, 
fini=<optimized out>, rtld_fini=<optimized out>,
     stack_end=0x7fffffffdc18) at libc-start.c:274

Aug 25 2014