mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
fix Issue 21432 - [CTFE] Cannot declare enum array in function scope
This commit is contained in:
parent
3805e2973a
commit
2e40bf2fe2
2 changed files with 33 additions and 3 deletions
|
@ -2352,6 +2352,7 @@ public:
|
|||
if (ExpInitializer ie = v._init.isExpInitializer())
|
||||
{
|
||||
result = interpretRegion(ie.exp, istate, goal);
|
||||
return;
|
||||
}
|
||||
else if (v._init.isVoidInitializer())
|
||||
{
|
||||
|
@ -2359,13 +2360,17 @@ public:
|
|||
// There is no AssignExp for void initializers,
|
||||
// so set it here.
|
||||
setValue(v, result);
|
||||
return;
|
||||
}
|
||||
else
|
||||
else if (v._init.isArrayInitializer())
|
||||
{
|
||||
result = v._init.initializerToExpression(v.type);
|
||||
if (result !is null)
|
||||
return;
|
||||
}
|
||||
e.error("declaration `%s` is not yet implemented in CTFE", e.toChars());
|
||||
result = CTFEExp.cantexp;
|
||||
}
|
||||
}
|
||||
else if (v.type.size() == 0)
|
||||
{
|
||||
// Zero-length arrays don't need an initializer
|
||||
|
|
25
compiler/test/compilable/test21432.d
Normal file
25
compiler/test/compilable/test21432.d
Normal file
|
@ -0,0 +1,25 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=21432
|
||||
auto issue21432()
|
||||
{
|
||||
enum int[] a = [];
|
||||
return a;
|
||||
}
|
||||
|
||||
enum test21432a = issue21432;
|
||||
|
||||
///////////////////////
|
||||
|
||||
double issue21432b(double r)
|
||||
{
|
||||
enum double[4] poly = [
|
||||
0x1.ffffffffffdbdp-2,
|
||||
0x1.555555555543cp-3,
|
||||
0x1.55555cf172b91p-5,
|
||||
0x1.1111167a4d017p-7,
|
||||
];
|
||||
|
||||
immutable r2 = r * r;
|
||||
return r + r2 * (poly[0] + r * poly[1]) + r2 * r2 * (poly[2] + r * poly[3]);
|
||||
}
|
||||
|
||||
enum test21432b = issue21432b(-0x1p-1);
|
Loading…
Add table
Add a link
Reference in a new issue