Bug 2550 – implicit conversions don't apply to template value parameter specialization
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-01-01T02:19:00Z
Last change time
2015-06-09T05:10:45Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
davidl
Comments
Comment #0 by davidl — 2009-01-01T02:19:21Z
template pow10(long n)
{
static if(n<0)
const long pow10=0;
else
const long pow10=10*pow10!(n-1);
}
template pow10(long n:0)
{
const long pow10=1;
}
static assert(pow10!(0) == 1);
Comment #1 by clugdbug — 2009-09-24T07:15:54Z
Original title: 'template specialization not working because of "static if"?'
It's not because of 'static if'. This shows the same problem:
template pow10(long n){
const long pow10=7;
}
template pow10(long n:0){
const long pow10=1;
}
static assert(pow10!(0) == 1);
It will compile if you put
static assert(pow10!(0L) == 1);
It seems that the compiler requires template value specialisations have to exactly match both type and value, but I don't see that in the spec anywhere. Probably a bug. It's certainly pretty annoying.