D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3476 - C-style initializer for structs must be disallowed for structs with a constructor
Summary: C-style initializer for structs must be disallowed for structs with a constru...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2009-11-05 13:55 UTC by Andrei Alexandrescu
Modified: 2015-06-09 05:14 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-11-05 13:55:02 UTC
struct S {
    int a;
    this(int) {}
}

S s = { 1 };

This code should not compile. The presence of the constructor means S's author wants to guard some invariant. The C-style constructor may initialize the object to an arbitrary value.
Comment 1 Kosmonaut 2009-12-12 14:06:50 UTC
Relevant SVN changeset:
http://www.dsource.org/projects/dmd/changeset/291
Comment 2 Walter Bright 2009-12-31 11:20:02 UTC
Fixed dmd 2.038