D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9161 - Linker error on linux if struct has @disabled ~this();
Summary: Linker error on linux if struct has @disabled ~this();
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2012-12-15 08:17 UTC by Dmitry Olshansky
Modified: 2022-07-07 10:16 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 Dmitry Olshansky 2012-12-15 08:17:16 UTC
The intent here is to agressively prevent people from using struct that is only meant as a namespace and thus contains only static methods & opCall/opDispatch etc.

The sample below with fine on Win32 but fails to link on Linux 64-bit:

public struct dummy
{    
    static auto opCall(C)(in C[] name)
    {
        return name;       
    }

    @disable ~this(); //comment this out to avoid error
}

void main()
{
    assert(dummy("ABCDE") == "ABCDE");
}

The error message is:

test_case.o:(.data._D26TypeInfo_S9test_case5dummy6__initZ+0x58): undefined reference to `_D9test_case5dummy6__dtorMFZv'

That is the destructor symbol is not found - correct it shouldn't been there, but apparently it's referenced all the same.
Comment 1 David Nadlinger 2012-12-15 08:31:39 UTC
Shouldn't we just emit a null pointer into the struct TypeInfo for disabled dtors?
Comment 2 Dmitry Olshansky 2012-12-22 13:05:17 UTC
(In reply to comment #1)
> Shouldn't we just emit a null pointer into the struct TypeInfo for disabled
> dtors?

I do think it's the same as @disable this(); i.e. changes semantics so that you literally can't call destructor even statically. And on win32 I'm seeing just that.
Comment 3 Dlang Bot 2022-07-07 05:05:10 UTC
@Geod24 updated dlang/dmd pull request #14272 "Fix 18973 - TypeInfo generation does not account for `@disable`" fixing this issue:

- Fix 9161 - Linker error if struct has disabled dtor

https://github.com/dlang/dmd/pull/14272
Comment 4 Dlang Bot 2022-07-07 10:16:20 UTC
dlang/dmd pull request #14272 "Fix 18973, 9161 - TypeInfo generation does not account for `@disable`" was merged into master:

- 4df133b57411383be4721685f594ff8ab193f56d by Geod24:
  Fix 9161 - Linker error if struct has disabled dtor

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