mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
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:
parent
635aeb79c2
commit
295b0008e4
9 changed files with 105 additions and 65 deletions
18
compiler/test/fail_compilation/cpp_cast.d
Normal file
18
compiler/test/fail_compilation/cpp_cast.d
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue