Thread overview
unclear compile error for struct with string template
Aug 25, 2014
Oleg B
Aug 25, 2014
bearophile
Aug 25, 2014
Oleg B
Aug 25, 2014
Oleg B
August 25, 2014
[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]
August 25, 2014
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
August 25, 2014
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?
August 25, 2014
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
#0  0x000000000046c39a in ctfeInterpret(Expression*) ()
#1  0x0000000000457012 in deduceType(RootObject*, Scope*, Type*, Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, unsigned long)::DeduceType::visit(TypeInstance*) ()
#2  0x000000000044e304 in deduceType(RootObject*, Scope*, Type*, Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, unsigned long) ()
#3  0x000000000045224f in deduceType(RootObject*, Scope*, Type*, Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, unsigned long)::DeduceType::visit(TypeStruct*) ()
#4  0x0000000000455e80 in deduceType(RootObject*, Scope*, Type*, Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, unsigned long)::DeduceType::visit(Expression*) ()
#5  0x000000000044e32c in deduceType(RootObject*, Scope*, Type*, Array<TemplateParameter*>*, Array<RootObject*>*, unsigned int*, unsigned long) ()
#6  0x0000000000458251 in TemplateDeclaration::deduceFunctionTemplateMatch(TemplateInstance*, Scope*, FuncDeclaration*&, Type*, Array<Expression*>*) ()
#7  0x000000000045caf1 in functionResolve(Match*, Dsymbol*, Loc, Scope*, Array<RootObject*>*, Type*, Array<Expression*>*)::ParamDeduce::fp(void*, Dsymbol*) ()
#8  0x00000000004dd577 in overloadApply(Dsymbol*, void*, int (*)(void*, Dsymbol*)) ()
#9  0x000000000045c401 in functionResolve(Match*, Dsymbol*, Loc, Scope*, Array<RootObject*>*, Type*, Array<Expression*>*) ()
#10 0x00000000004e0343 in resolveFuncCall(Loc, Scope*, Dsymbol*, Array<RootObject*>*, Type*, Array<Expression*>*, int) ()
#11 0x00000000004d9522 in CallExp::semantic(Scope*) ()
#12 0x00000000004eef56 in ExpInitializer::inferType(Scope*) ()
#13 0x00000000004b08ad in VarDeclaration::semantic(Scope*) ()
#14 0x00000000004c1f7a in DeclarationExp::semantic(Scope*) ()
#15 0x000000000043cd3b in ExpStatement::semantic(Scope*) ()
#16 0x00000000004479a6 in CompoundStatement::semantic(Scope*) ()
#17 0x00000000004e5e2a in FuncDeclaration::semantic3(Scope*) ()
#18 0x0000000000407b28 in Module::semantic3() ()
#19 0x00000000004051bc in tryMain(unsigned long, char const**) ()
#20 0x000000338be21b45 in __libc_start_main (main=0x406e60 <main>, argc=4, ubp_av=0x7fffffffdc28, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
    stack_end=0x7fffffffdc18) at libc-start.c:274
#21 0x0000000000402739 in _start ()