Bug 17309 – [REG 2.073.2] constructor template doesn't infer `pure`

Status
RESOLVED
Resolution
WONTFIX
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-04-08T13:01:00Z
Last change time
2017-04-18T13:12:31Z
Keywords
rejects-valid
Assigned to
nobody
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2017-04-08T13:01:04Z
Found by Russel Winder who posted to D.learn: http://forum.dlang.org/post/[email protected] ---- struct BigInt { this(Range)(Range s) {} /* `pure` should be inferred, but apparently isn't */ } void main() { auto y = immutable BigInt(""); /* rejected, should be accepted */ } ---- Exact error message: ---- test.d(8): Error: template test.BigInt.__ctor cannot deduce function from argument types !()(string) immutable, candidates are: test.d(3): test.BigInt.__ctor(Range)(Range s) ----
Comment #1 by bugzilla — 2017-04-11T09:18:59Z
If the constructor is marked as 'immutable', it compiles. It also compiles with dmd 2.070, didn't check other versions.
Comment #2 by bugzilla — 2017-04-18T09:46:40Z
(In reply to Walter Bright from comment #1) > It also compiles with dmd 2.070, didn't check other versions. I don't know what I did there. I can't get it to compile with any dmd versions I tried, so I don't think this is a regression.
Comment #3 by bugzilla — 2017-04-18T09:52:17Z
I think that trouble here is that attribute inference is not done until the template is instantiated. But the compiler does not instantiate a template until it matches a template, and this(Range)(Range s) does not match for constructing an immutable. I don't see a way out of this chicken-and-egg problem. I'm going to mark this as invalid.
Comment #4 by ag0aep6g — 2017-04-18T13:12:31Z
(In reply to Walter Bright from comment #3) > I think that trouble here is that attribute inference is not done until the > template is instantiated. But the compiler does not instantiate a template > until it matches a template, and > > this(Range)(Range s) > > does not match for constructing an immutable. I don't see a way out of this > chicken-and-egg problem. > > I'm going to mark this as invalid. 1) That's a major bummer. 2) It means that Russel's issue is a phobos regression. I've filed it separately as issue 17330.