Bug 9073 – In manifest constant initializer, && and || should evaluate their operands lazily.
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-25T00:56:18Z
Last change time
2018-01-02T20:45:06Z
Keywords
pull
Assigned to
No Owner
Creator
Kenji Hara
Comments
Comment #0 by k.hara.pg — 2012-11-25T00:56:18Z
With and without `version=expected`, this code should work, but doesn't.
bool foo(alias pred)()
{
version(expected)
{
// doesn't work, but should
enum isLessThan = (is(typeof(pred) : string) && pred == "a < b");
}
else
{
// works as expected
static if (is(typeof(pred) : string) && pred == "a < b")
enum isLessThan = true;
else
enum isLessThan = false;
}
return isLessThan;
}
void main()
{
assert(foo!("a < b")() == true);
assert(foo!((a,b) => a<b)() == false);
}
Manifest constant declaration is always evaluated in compile time, so I think there is no problem.