D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15500 - default construction disabled for struct constructor with default arguments
Summary: default construction disabled for struct constructor with default arguments
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
: 15515 15551 (view as issue list)
Depends on:
Blocks:
 
Reported: 2016-01-03 01:43 UTC by Timothee Cour
Modified: 2016-03-29 22:23 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timothee Cour 2016-01-03 01:43:04 UTC
$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 ag0aep6g 2016-01-04 19:52:05 UTC
*** Issue 15515 has been marked as a duplicate of this issue. ***
Comment 2 Martin Nowak 2016-01-04 22:42:47 UTC
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 John Colvin 2016-01-04 23:43:16 UTC
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 Martin Nowak 2016-01-05 11:05:13 UTC
(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 github-bugzilla 2016-01-05 22:15:58 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://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 github-bugzilla 2016-01-24 22:47:49 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0122225c1eb7b4c92a5060fefbc5cae498818d39
fix Issue 15500 - default construction disabled for struct constructor with default arguments

https://github.com/D-Programming-Language/dmd/commit/e50f8aa63356b767c713b50c4d944e9b28345de7
Merge pull request #5331 from MartinNowak/fix15500
Comment 8 Martin Nowak 2016-03-29 22:23:46 UTC
*** Issue 15551 has been marked as a duplicate of this issue. ***