Bug 18493 – [betterC] Can't use aggregated type with postblit

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-02-22T12:56:55Z
Last change time
2023-04-08T09:53:18Z
Keywords
betterC, industry, pull
Assigned to
No Owner
Creator
Radu Racariu
See also
https://issues.dlang.org/show_bug.cgi?id=18828

Comments

Comment #0 by radu.racariu — 2018-02-22T12:56:55Z
The following compiled with '-betterC': ===================================== @nogc nothrow: struct S { @nogc nothrow: this(this) { impl++; } ~this() { } int* impl; } struct C { S s1; S s2; } extern(C) int main() { return 0; } ===================================== Produces a meaningless error (no line number no file name): `Error: Cannot use try-catch statements with -betterC` Commenting either the postblit ctor or dtor makes the error go away. Expected: To get no error.
Comment #1 by radu.racariu — 2018-02-22T13:01:38Z
Errors out on dmd 2.0.78.3 and dmd 2.0.79-beta1 https://run.dlang.io/is/R6BWSz
Comment #2 by radu.racariu — 2018-03-26T07:05:08Z
Even more reduced test case: --- struct S { this(this) { } ~this() { } } struct C { S s1; S s2; } ---
Comment #3 by radu.racariu — 2018-04-17T05:44:45Z
Declaring `C` as --- struct C { S s1; } --- makes the test case compile.
Comment #4 by slavo5150 — 2018-04-18T03:34:26Z
A PR has been submitted to remove generation of the try-catch if the postblit is `nothrow`: https://github.com/dlang/dmd/pull/8184 I don't consider this a complete fix to this issue, but if it is accepted, it will allow one to attribute their postblit with `nothrow` to avoid the error in -betterC. I'm pondering a more thorough solution for -betterC, and intend to tackle that as another PR.
Comment #5 by radu.racariu — 2018-04-18T08:00:20Z
Ideally -betterC should imply `nothrow`, and any lowered code should work with this assumption. What is important to keep in mind is that if you require `this(this)` to be annotated with `nothrow` in order to compile - you need to fix the error message for the case where it isn't and using -betterC, the current error message is very bad.
Comment #6 by radu.racariu — 2018-04-26T07:18:22Z
I though more about this and I think betterC should imply nothrow *only for* compiler generated code. Making betterC nothrow by default will change semantics and basically split the language in two, as betterC code will have 2 different defaults depending on the switch. This means that betterC should start error out on non nothrow code, with a deprecation period for interim.
Comment #7 by github-bugzilla — 2018-04-28T10:48:51Z
Comment #8 by github-bugzilla — 2018-06-12T07:32:06Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/d676ffa836204dded541101b74dff8ae8131ad5d Fix Issue 18493 - [betterC] Can't use aggregated type with postblit https://github.com/dlang/druntime/commit/a2cabb8e668434521aff45f4d064fcf48780fb11 Merge pull request #2184 from JinShil/betterC_nothrow Fix Issue 18493 - [betterC] Can't use aggregated type with postblit merged-on-behalf-of: Sebastian Wilzbach <[email protected]>
Comment #9 by slavo5150 — 2018-06-12T07:37:14Z
This is not yet fixed. Still needs https://github.com/dlang/dmd/pull/8253 and maybe some more druntime work.
Comment #10 by dlang-bot — 2023-04-04T11:38:07Z
@RazvanN7 created dlang/dmd pull request #15076 "Fix Issue 18493 - [betterC] Can't use aggregated type with postblit" fixing this issue: - Fix Issue 18493 - [betterC] Can't use aggregated type with postblit https://github.com/dlang/dmd/pull/15076
Comment #11 by dlang-bot — 2023-04-08T09:53:18Z
dlang/dmd pull request #15076 "Fix Issue 18493 - [betterC] Can't use aggregated type with postblit" was merged into master: - 490c8a26f6563e86b9df3cd4180afc2e6c8bb08c by RazvanN7: Fix Issue 18493 - [betterC] Can't use aggregated type with postblit https://github.com/dlang/dmd/pull/15076