D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22951 - Dtor missing from generated C++ header
Summary: Dtor missing from generated C++ header
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-03-28 16:35 UTC by moonlightsentinel
Modified: 2022-03-29 07:58 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2022-03-28 16:35:37 UTC
dtoh omits function declarations that cannot be called from C++. But that currently applies to destructors and hence allow code that breaks RAII due to instances not being destroyed on the C++ side.
Comment 1 Dlang Bot 2022-03-29 06:56:13 UTC
@MoonlightSentinel created dlang/dmd pull request #13914 "Fix 22951 - Emit non-extern (C++) destructors as private members" fixing this issue:

- Fix 22951 - Emit non-extern (C++) destructors as private members
  
  Destructors not marked as `extern (C++)` aren't accessible from C++
  due to the D name mangling. The header generator used to skip `extern(D)`
  destructors, allowing C++ code that violated RAII guarantees.
  
  Declaring the constructors as `private` members ensures that any
  instance that would need to be destroyed on the C++ side causes a
  compiler error (rather than a linker error due to missmatched mangling).
  
  Renamed the helper function `checkVirtualFunction` because it now also
  handles other types of functions.

https://github.com/dlang/dmd/pull/13914
Comment 2 Dlang Bot 2022-03-29 07:58:30 UTC
dlang/dmd pull request #13914 "Fix 22951 - Emit non-extern (C++) destructors as private members" was merged into master:

- 11be8a63105cb5e43b4a2c318260bafb8456af32 by MoonlightSentinel:
  Fix 22951 - Emit non-extern (C++) destructors as private members
  
  Destructors not marked as `extern (C++)` aren't accessible from C++
  due to the D name mangling. The header generator used to skip `extern(D)`
  destructors, allowing C++ code that violated RAII guarantees.
  
  Declaring the constructors as `private` members ensures that any
  instance that would need to be destroyed on the C++ side causes a
  compiler error (rather than a linker error due to missmatched mangling).
  
  Renamed the helper function `checkVirtualFunction` because it now also
  handles other types of functions.

https://github.com/dlang/dmd/pull/13914