http://d.puremagic.com/issues/show_bug.cgi?id=8637
Summary: Enforcement and purity Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: nob...@puremagic.com ReportedBy: monarchdo...@gmail.com --- Comment #0 from monarchdo...@gmail.com 2012-09-10 02:58:42 PDT --- The argument taken by enforce must be "castable to bool", so the the implementation can do the cast. However, enforce is declared pure, so if the cast operator is not pure, the compilation fails: -------- import std.regex; import std.exception; void main() { auto m = match("hello world", regex("world")); assert(m); //<- Fine enforce(m); //Here } -------- Error: pure function 'enforce' cannot call impure function '~this' Error: pure function 'enforce' cannot call impure function 'opCast' -------- The messages come from: -------- T enforce(T)(T value, lazy const(char)[] msg = null, string file = __FILE__, size_t line = __LINE__) @safe pure { if (!value) bailOut(file, line, msg); return value; } -------- "if(!value)": This makes an impure call to opCast. "enforce(T)(T value..." This uses pass by value, and makes an impure call to the destructor I have no idea what a good fix would be. Regarding pass by value, wouldn't this be a textbook example of using "auto ref" with "auto return"? I have no idea... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------