[Issue 22635] New: opCast prevent calling destructor for const this.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 29 08:28:09 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22635
Issue ID: 22635
Summary: opCast prevent calling destructor for const this.
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: submada at gmail.com
This code doesn't compile:
```d
struct Foo{
bool opCast(T : bool)()const{
assert(0);
}
~this(){}
}
struct Bar{
const Foo foo;
}
void main(){
}
```
Error: template instance `opCast!(Foo)` does not match template declaration
`opCast(T : bool)()`
Generated constructor Bar.~dtor is using Foo.opCast to remove const from foo
before calling Foo.~this.
Right way is to take address of foo and cast pointer without involvement of
Foo.opCast.
This bug prevent emplacing qualified struct with opCast + ~this(). Example:
```d
struct Foo{
bool opCast(T : bool)()const{
assert(0);
}
this(int i){}
~this(){}
}
void main(){
import core.lifetime : emplace;
void[Foo.sizeof] buffer = void;
emplace(cast(const Foo*)&buffer, 42);
}
```
Error: template instance `opCast!(Foo)` does not match template declaration
`opCast(T : bool)()`
--
More information about the Digitalmars-d-bugs
mailing list