D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3269 - pure functions silently become nothrow
Summary: pure functions silently become nothrow
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2009-08-28 11:05 UTC by Andrei Alexandrescu
Modified: 2015-06-09 01:20 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-08-28 11:05:13 UTC
class A
{
    pure static void raise(string s)
    {
        throw new Exception(s);
    }
}

void main()
{
    A.raise("a");
}

This code compiles and runs without an error!
Comment 1 Don 2009-10-27 12:22:53 UTC
// A pure function might have side effects, unless it is also nothrow.
// PATCH:     e2ir.c, line 288.
     
    e = el_una(op,tyret,ep);
    }
    else if (ep) {
-	e = el_bin(tf->ispure ? OPcallns : OPcall,tyret,ec,ep);
+	e = el_bin((tf->ispure && tf->isnothrow) ? OPcallns : OPcall,tyret,ec,ep);
	}
    else {
-	e = el_una(tf->ispure ? OPucallns : OPucall,tyret,ec);
+	e = el_una((tf->ispure && tf->isnothrow) ? OPucallns : OPucall,tyret,ec);
	}

    if (retmethod == RETstack)
Comment 2 Leandro Lucarella 2009-10-29 14:38:17 UTC
Related SVN revision: http://www.dsource.org/projects/dmd/changeset/226
Comment 3 Walter Bright 2009-11-06 11:33:47 UTC
Fixed dmd 2.036