Bug 1300 – Issues with struct in compile-time function
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-06-30T07:40:00Z
Last change time
2014-02-16T15:24:20Z
Assigned to
bugzilla
Creator
samukha
Comments
Comment #0 by samukha — 2007-06-30T07:40:03Z
May be related to 1204
struct Bar
{
int x;
}
int foo()
{
// Fails with 'Error: cannot cast int to Bar' if explicit initialization is omitted:
Bar b = Bar.init;
b.x = 1;
b = bar(b); // Error: cannot evaluate foo() at compile time
return b.x;
}
Bar bar(Bar b)
{
return b;
}
void main(char[][] args)
{
static x = foo();
}
Comment #1 by samukha — 2007-06-30T08:41:39Z
More test cases:
struct Bar
{
int x;
}
int foo()
{
Bar b = Bar.init;
b.x = 100;
for (size_t i = 0; i < b.x; i++) // b.x is the stumbling block here
{
}
b.x++; // fails while b.x = b.x + 1 works
return b.x;
}
void main(char[][] args)
{
static x = foo();
}