[Issue 15866] New: casting away const from "super" results in "this"
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Apr 3 06:36:26 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15866
Issue ID: 15866
Summary: casting away const from "super" results in "this"
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: r.sagitario at gmx.de
class A
{
int foo(bool) { return 'a'; }
}
class B : A
{
override int foo(bool b) const { return b ? 'b' : (cast()super).foo(b); }
}
void main()
{
B b = new B;
assert(b.foo(false) == 'a');
}
This code causes a stack overflow because (cast()super).foo(b) calls B.foo, not
A.foo.
I've found this pattern while debugging something else in
OutOfMemoryError.toString.
It is also used in std.xml.Document.toHash, so maybe issue 14966 is related.
--
More information about the Digitalmars-d-bugs
mailing list