Bug 23957 – Casting to derived extern(C++) class is unsafe

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-06-03T12:31:09Z
Last change time
2024-06-12T11:49:56Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Nick Treleaven
See also
https://issues.dlang.org/show_bug.cgi?id=21690

Comments

Comment #0 by nick — 2023-06-03T12:31:09Z
extern(C++) class C { void f() { } } extern(C++) class D : C { } void main() @safe { assert(cast(D)(new C) is null); // would fail as RTTI not checked auto c = cast(C)(new D); // OK } PR incoming.
Comment #1 by dlang-bot — 2023-06-03T12:35:40Z
@ntrel created dlang/dmd pull request #15294 "Fix Issue 23957 - Casting to derived extern(C++) class is unsafe" fixing this issue: - Fix Issue 23957 - Casting to derived extern(C++) class is unsafe https://github.com/dlang/dmd/pull/15294
Comment #2 by dlang-bot — 2023-06-10T11:09:17Z
@ntrel updated dlang/dlang.org pull request #3619 "[spec/function] Improve `return` struct method attribute docs" fixing this issue: - [spec/function] Document `return` parameters without `scope` Fixes Issue 23957 - Casting to derived extern(C++) class is unsafe. Part of Issue 17934 - [scope] scopeness entrypoint for unique/ref-counted missing. Add 'Struct Return Methods' subheading. https://github.com/dlang/dlang.org/pull/3619
Comment #3 by nick — 2023-06-10T13:08:41Z
The above pull is unrelated, and has been removed from its commit message.
Comment #4 by dlang-bot — 2023-07-14T18:22:17Z
@ntrel updated dlang/dmd pull request #15293 "Disallow dynamic cast to extern(C++) class" fixing this issue: - Fix Issue 23957 - Casting to derived extern(C++) class is unsafe https://github.com/dlang/dmd/pull/15293
Comment #5 by dlang-bot — 2024-06-12T11:49:56Z
dlang/dmd pull request #15294 "Fix Issue 23957 - Casting to derived extern(C++) class is unsafe" was merged into master: - a26f34fe0d7e314e221c5411f628c5fc40682d4b by Nick Treleaven: Fix Bugzilla 23957 - Casting to derived extern(C++) class is unsafe https://github.com/dlang/dmd/pull/15294