dmd/compiler/test/fail_compilation/cpp_cast.d
Nick Treleaven 295b0008e4
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>
2024-06-12 13:49:50 +02:00

18 lines
442 B
D

// 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
}