[Issue 11461] `Error`s are not thrown as `pure nothrow` functions are optimized out with "-O -release"

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 15 01:24:09 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11461


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #4 from monarchdodra at gmail.com 2013-11-15 01:23:58 PST ---
(In reply to comment #2)
> (In reply to comment #1)
> > Well, if a function has no side effect and does not produce a result or the
> > result isn't used, there is no point in calling it. It's pretty harsh to demand
> > that the compiler always calls such functions only to support the minor
> > noreturn use-case.
> 
> Minor or no it is documented `pure` functions can throw and the compiler
> already consider `pure` but not `nothrow` functions as doing this (i.e. they
> aren't optimized out). So `nothrow` must be treated the same way as `nothrow`
> just means no recoverable `Exception`s are thrown. Breaking language changes
> are welcome but in a separate enhancement issue. Currently `onOutOfMemoryError`
> is no-op because of this and the issue should be fixed.

I don't know... an "Error" isn't really considered as "observable program
behavior", is it? If a function is (either strongly or weakly) pure, takes no
reference arguments, and is nothrow, then it calling it will not have
observable side effect, and can (and IMO should) be optimized out.

This can be workaround simply by forcing the function to look like it can have
"observable side effects", as so:

//----
void f(void* = null) pure nothrow
{ throw new Error(""); }

void main()
{ f(); }
//----

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list