Bug 11091 – Deduced purity doesn't work?

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-22T02:49:00Z
Last change time
2013-09-22T04:15:34Z
Assigned to
nobody
Creator
simendsjo

Comments

Comment #0 by simendsjo — 2013-09-22T02:49:35Z
Tried running dmd+phobos head at some code, but got errors. This is probably the breaking change: https://github.com/D-Programming-Language/phobos/commit/7714a9c42e2cc8d794a5ee483fdd49d52995b3ac import std.exception; class E: Exception { this(string msg, string file=__FILE__, size_t line=__LINE__) { super(msg, file, line); } } void f() pure { enforceEx!E(true); } void main() { f(); } // Error: pure function 't.f' cannot call impure function 'std.exception.enforceEx!(E).enforceEx!bool.enforceEx
Comment #1 by k.hara.pg — 2013-09-22T04:15:34Z
This is expected change in git-head, introduced by fixing bug 10254. In the OP code, the constructor in E is not annotated with pure. So, the expression object creation new E("msg") is essentially impure. But in 2.063 and earlier, NewExpression had wrongly ignored the called constructor purity and safety (== bug 10254). Then enforceEx!E had been also incorrectly deduced to pure.