D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2526 - (D1 only) non-const initializer to constant accepted inside template
Summary: (D1 only) non-const initializer to constant accepted inside template
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: accepts-invalid, wrong-code
: 2706 (view as issue list)
Depends on:
Blocks:
 
Reported: 2008-12-20 04:00 UTC by Christian Kamm
Modified: 2019-05-11 17:01 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Christian Kamm 2008-12-20 04:00:50 UTC
This compiles and fails the assert:

template T() { const o = new Object; }
void main() { assert(T!().o is T!().o); }

It should not compile, as
const o = new Object;
also fails with "Error: non-constant expression new Object".

The assert is triggered because DMD emits a call to new for each mention of T!().o inside a function.
Comment 1 yebblies 2012-01-29 22:22:56 UTC
D2 bug is duplicate of issue 2414.
Comment 2 yebblies 2012-01-29 22:23:06 UTC
*** Issue 2706 has been marked as a duplicate of this issue. ***
Comment 3 yebblies 2012-02-01 20:32:19 UTC
*** Issue 4397 has been marked as a duplicate of this issue. ***
Comment 4 Mathias LANG 2019-05-11 17:01:40 UTC
D1 only, works in D2