D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3259 - Dynamic Initialization of Structs fails type check for some cases
Summary: Dynamic Initialization of Structs fails type check for some cases
Status: RESOLVED DUPLICATE of issue 2702
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: accepts-invalid
: 3302 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-08-19 04:50 UTC by HOSOKAWA Kenchi
Modified: 2015-06-09 01:28 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 HOSOKAWA Kenchi 2009-08-19 04:50:34 UTC
struct S {/* containing anything except reference for class or array */}
struct T {/* containing anything */}
class C {}

void main()
{
	//	invalid initialization is accepted
	S a = T();
	S b = 1;

	//	valid error in compile time : dynamic initilizer of struct
	S c = 1.0;	// cannot cast double to S
	S d = new T;
	S e = new C;
	S f = new int[1];

	//	valid error in compile time : assignment
	a = T();
	b = 1;
}

It seems this problem results from implicit cast in the dynamic initialization of structs.
It is highly severe when both S and T contain only integer type.

In C, any named enum is treated as int.
This problem resembles that.
Comment 1 HOSOKAWA Kenchi 2009-09-05 19:20:39 UTC
*** Issue 3302 has been marked as a duplicate of this issue. ***
Comment 2 Don 2009-09-07 01:16:45 UTC
This is a duplicate of bug 2702, which already has a patch. I've confirmed that the patch fixes this case and bug 3202. Vote for 2702! I think it's quite serious.

*** This issue has been marked as a duplicate of issue 2702 ***