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.
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
@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