Bug 772 – Bogus error using relation operator as static if expression within template
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-12-30T00:42:00Z
Last change time
2014-02-15T13:22:24Z
Assigned to
bugzilla
Creator
ibisbasenji
Comments
Comment #0 by ibisbasenji — 2006-12-30T00:42:44Z
Given the following useless test program...
--------------------------------------------------
module bug ;
template foo (ulong n) {
static if (n < 10_LU) {
const foo = n ;
}
else {
const foo = n % 10 ;
}
}
void main () {
ulong a = 1_LU ;
auto omega = foo!(a);
}
--------------------------------------------------
The compiler will output:
bug.d(4): Error: expression (a) < 10LU does not evaluate to a boolean
bug.d(15): template instance bool0.main.foo!(a) error instantiating
const should be added to the variable declaration, so the error message is correct. Add const and it works in DMD 2.020 and 1.033.
module bug ;
template foo (ulong n) {
static if (n < 10_LU) {
const foo = n ;
}
else {
const foo = n % 10 ;
}
}
void main () {
const ulong a = 1_LU ; // <- added const
auto omega = foo!(a);
}