Bug 21390 – Cannot declare extern (storage class) variable of type with disabled default construction
Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-11-13T18:59:44Z
Last change time
2022-02-28T09:44:46Z
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2020-11-13T18:59:44Z
Cannot have extern (storage class) variable of type with disabled default construction.
---
struct S { @disable this(); }
// Does not compile: "default construction is disabled for type `S`"
extern __gshared S gVariable1;
// Does not compile: "extern symbols cannot have initializers"
extern __gshared S gVariable2 = S.init;
---
Comment #1 by dlang-bot — 2022-02-28T00:24:12Z
@thewilsonator created dlang/dmd pull request #13733 "Add test case for Issue 21390" mentioning this issue:
- Add test case for Issue 21390
https://github.com/dlang/dmd/pull/13733
Comment #2 by iamthewilsonator — 2022-02-28T00:25:39Z
struct S { @disable this(); }
// Does not compile: "default construction is disabled for type `S`"
extern __gshared S gVariable1;
Works Yields
Up to 2.063 : Failure with output: onlineapp.d(4): Error: variable onlineapp.gVariable1 initializer required for type S
2.064 to 2.078.1: Failure with output: onlineapp.d(4): Error: variable onlineapp.gVariable1 default construction is disabled for type S
2.079.1 to 2.095.1: Failure with output: onlineapp.d(4): Error: variable `onlineapp.gVariable1` default construction is disabled for type `S`
Since 2.096.1: Success and no output
I'm presuming that
// Does not compile: "extern symbols cannot have initializers"
extern __gshared S gVariable2 = S.init;
was an attempted workaround, as that will probably be a WONTFIX.
That leaves this as WORKSFORME
Comment #3 by dlang-bot — 2022-02-28T09:44:46Z
dlang/dmd pull request #13733 "Add test case for Issue 21390" was merged into master:
- 971c532be017a0826a9440923c2457b71b4cf8c6 by Nicholas Wilson:
Add test case for Issue 21390
https://github.com/dlang/dmd/pull/13733