Bug 1407 – auto type inference on new const(Class)() doesn't infer const
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-08-09T15:41:00Z
Last change time
2015-06-09T01:14:14Z
Keywords
rejects-valid
Assigned to
nobody
Creator
paching
Comments
Comment #0 by paching — 2007-08-09T15:41:34Z
Also true for invariant. Sample code:
class A {}
void main() {
auto b = new const(A)();
auto c = new invariant(A)();
}
Gives two errors such as:
Error: cannot implicitly convert expression (new const A) of type const A to testcase.A
Error: cannot implicitly convert expression (new invariant A) of type invariant A to testcase.A
Comment #1 by witold.baryluk+d — 2007-08-11T12:54:52Z
Mayby extend type inference to
auto(auto) b = new const(A)();
First auto will expand to storage type, and second to name of class
This will allow to do this:
invariant(auto) b = new const(A)()
and also:
const(auto) b = new A();
Comment #2 by witold.baryluk+d — 2007-08-11T12:56:13Z
(In reply to comment #1)
> invariant(auto) b = new const(A)()
Should be:
const(auto) b = new invariant(A)()
Comment #3 by yebblies — 2011-06-09T09:36:17Z
This has been fixed for a while, if you change 'invariant' to 'immutable'.