Bug 15500 – default construction disabled for struct constructor with default arguments
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-03T01:43:00Z
Last change time
2016-03-29T22:23:46Z
Keywords
pull
Assigned to
nobody
Creator
timothee.cour2
Comments
Comment #0 by timothee.cour2 — 2016-01-03T01:43:04Z
$dmd_068_X -c -o- $bugs_D/bug_D20160102T173458.d
ok
DMD64 D Compiler v2.069-devel-6b2b521
dmd -c -o- $bugs_D/bug_D20160102T173458.d
Error: variable a default construction is disabled for type A
----
struct A{
this(int a=0){
}
}
void fun(){
static A a;
}
----
Comment #1 by ag0aep6g — 2016-01-04T19:52:05Z
*** Issue 15515 has been marked as a duplicate of this issue. ***
Comment #2 by code — 2016-01-04T22:42:47Z
According to Andrej it's supposed to be a warning only.
https://github.com/D-Programming-Language/dmd/pull/5185#issuecomment-168821489
But the changed code triggers an error due to a disabled constructor.
----
cat > bug.d << EOF
struct S {
this(string r = ".") {
}
}
void test() {
S s;
}
EOF
dmd -c -w bug
----
bug.d(2): Warning: constructor bug.S.this default constructor for structs only allowed with @disable, no body, and no parameters
bug.d(7): Error: variable bug.test.s default construction is disabled for type S
----
Comment #3 by john.loughran.colvin — 2016-01-04T23:43:16Z
Am I missing something? I assumed this would just be a straightforward "structs cannot have a 0-arg constructor, even by using default arguments", regardless of use. Why push the error message down to the user of the struct? Any use case of the default argument is an error, therefore the default arguement should itself be an error.
Comment #4 by code — 2016-01-05T11:05:13Z
(In reply to John Colvin from comment #3)
> Am I missing something? I assumed this would just be a straightforward
> "structs cannot have a 0-arg constructor, even by using default arguments",
> regardless of use.
It is build that way, only a warning for now, but something went wrong and now there is an additional error on usage.
Comment #6 by github-bugzilla — 2016-01-05T22:15:58Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmdhttps://github.com/D-Programming-Language/dmd/commit/0122225c1eb7b4c92a5060fefbc5cae498818d39
fix Issue 15500 - default construction disabled for struct constructor with default arguments
- fix implementation of #5185, the new check should only
be a deprecation warning for now, but inadvertently
disabled default initialization (`S s;`) by setting
sd.noDefaultCtor
- simplify logic and control flow (only need to check whether
the first parameter has a default argument)
- still allow any kind of variadic constructor (doesn't make
sense to distinguish C from D-style variadics)
We might deprecate those called w/ zero arguments
(`auto s = S();`) on the call-site, but disallowing them
in general seems to drastic.
- Use a deprecation instead of a warning, since using
the -dw switch as default we agreed to no longer abuse
warnings for deprecations, so that people can cleanly compile
with -w. Edgy people insisting on using -de have to immediately
deal w/ deprecations.
https://github.com/D-Programming-Language/dmd/commit/e50f8aa63356b767c713b50c4d944e9b28345de7
Merge pull request #5331 from MartinNowak/fix15500
fix Issue 15500 - default construction disabled for struct constructor with default arguments
Comment #7 by github-bugzilla — 2016-01-24T22:47:49Z