[Issue 22186] New: [REG2.096] CTFE pure cast of function no longer allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 6 14:05:34 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22186
Issue ID: 22186
Summary: [REG2.096] CTFE pure cast of function no longer
allowed
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: johanengelen at weka.io
Testcase:
```
//reinterpreting cast from `nothrow @nogc @system void(void delegate() nothrow
@nogc @system func)*` to `pure nothrow @nogc @system void(void delegate()
nothrow @nogc @system)*`
import std.traits;
auto as(string addAttrsStr, Func)(scope Func func)
{
enum addAttrs = FunctionAttribute.pure_;
enum oldAttrs = functionAttributes!Func;
enum intersection = oldAttrs & addAttrs;
static assert(0 == intersection, Func.stringof ~ " already has attrs
pure");
enum newAttrs = oldAttrs | addAttrs;
static auto callFuncCtfe(Func func) { return func(); }
static auto callCasted(Func func) {
if(__ctfe) {
return (cast(SetFunctionAttributes!(typeof(&callFuncCtfe),
functionLinkage!callFuncCtfe, newAttrs))&callFuncCtfe)(func);
}
return (cast(SetFunctionAttributes!(typeof(func), functionLinkage!func,
newAttrs))func)();
}
return callCasted(func);
}
version = BUG_WITH_VOID;
version(BUG_WITH_VOID)
{
auto foo() {
void delegate() dg = delegate() { };
as!"pure"(dg);
return 1;
}
}
else
{
auto foo() {
int delegate() dg = delegate() { return 1; };
as!"pure"(dg);
return 1;
}
}
enum a = foo();
```
The compile error since 2.096 is:
```
test.d(17): Error: reinterpreting cast from `@system void(void delegate()
func)*` to `pure @system void(void delegate())*` is not supported in CTFE
test.d(22): called from here: `callCasted(func)`
test.d(32): called from here: `as(dg)`
test.d(46): called from here: `foo()`
```
Digger says this regression was introduced by:
https://github.com/dlang/dmd/pull/12090
--
More information about the Digitalmars-d-bugs
mailing list