Fix Issue 23957 - Casting to derived extern(C++) class is unsafe (#15294)

Fix Issue 23957 - Casting to derived extern(C++) class is unsafe

Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
This commit is contained in:
Nick Treleaven 2024-06-12 12:49:50 +01:00 committed by GitHub
parent 635aeb79c2
commit 295b0008e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 105 additions and 65 deletions

View file

@ -0,0 +1,18 @@
// See also: fail20000.d
/*
REQUIRED_ARGS: -de
TEST_OUTPUT:
---
fail_compilation/cpp_cast.d(16): Deprecation: cast from `cpp_cast.C` to `cpp_cast.D` not allowed in safe code
fail_compilation/cpp_cast.d(16): No dynamic type information for extern(C++) classes
---
*/
extern(C++) class C { void f() { } }
extern(C++) class D : C { }
void main() @safe
{
C c;
c = cast(D) new C; // reinterpret cast
c = cast(C) new D; // OK
}