Issue 18493 - [betterC] Can't use aggregated type with postblit
Summary: [betterC] Can't use aggregated type with postblit
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P1 blocker
Assignee: No Owner
URL:
Keywords: betterC, industry, pull
Depends on:
Blocks:
 
Reported: 2018-02-22 12:56 UTC by Radu Racariu
Modified: 2023-04-08 09:53 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Radu Racariu 2018-02-22 12:56:55 UTC
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 Radu Racariu 2018-02-22 13:01:38 UTC
Errors out on dmd 2.0.78.3 and dmd 2.0.79-beta1

https://run.dlang.io/is/R6BWSz
Comment 2 Radu Racariu 2018-03-26 07:05:08 UTC
Even more reduced test case:
---
struct S
{
    this(this)
    {
    }

    ~this()
    {
    }
}

struct C
{
    S s1;
    S s2;
}
---
Comment 3 Radu Racariu 2018-04-17 05:44:45 UTC
Declaring `C` as 

---
struct C
{
    S s1;
}
---

makes the test case compile.
Comment 4 Mike Franklin 2018-04-18 03:34:26 UTC
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 Radu Racariu 2018-04-18 08:00:20 UTC
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 Radu Racariu 2018-04-26 07:18:22 UTC
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 github-bugzilla 2018-04-28 10:48:51 UTC
Commit pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/8a33fb6c692d0b2c1f03ceeb65c28beaebd932a0
Add test for issue 18493
Comment 8 github-bugzilla 2018-06-12 07:32:06 UTC
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 <sebi.wilzbach@gmail.com>
Comment 9 Mike Franklin 2018-06-12 07:37:14 UTC
This is not yet fixed.  Still needs https://github.com/dlang/dmd/pull/8253 and maybe some more druntime work.
Comment 10 Dlang Bot 2023-04-04 11:38:07 UTC
@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 Dlang Bot 2023-04-08 09:53:18 UTC
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