Comment #0 by verylonglogin.reg — 2013-11-07T12:13:53Z
Error iff built with "-profile":
---
void main() nothrow
{ asm { nop; } } // Error: asm statements are assumed to throw
---
Documentation doesn't say `asm` can't be used in `nothrow` functions and IMO such restriction looks too strong. As a result some druntime (Issue 10260) and Phobos (Issue 10849) parts can't be used while profiling.
Let it be a "rejects-valid" bug for now.
Comment #1 by verylonglogin.reg — 2013-11-07T12:14:41Z
*** Issue 10260 has been marked as a duplicate of this issue. ***
Comment #2 by verylonglogin.reg — 2013-11-07T12:15:26Z
*** Issue 10849 has been marked as a duplicate of this issue. ***
Comment #3 by dlang-bugzilla — 2014-03-27T17:48:54Z
This really should be generating the same error with and without profile. I have no idea why it doesn't. For some reason the function's type is not marked as nothrow until _after_ the first time blockExit is run on it.
Comment #5 by blah38621 — 2014-06-08T17:59:19Z
I would agree that assuming asm statements always throw is not exactly useful,
especially as the inline asm statements are there for performance. Is there
some way that either the compiler could check to see if the asm actually
throws, or else for the user to tell the compiler that an ASM statement doesn't
throw?
Comment #6 by k.hara.pg — 2014-06-20T16:59:24Z
The root issue is in FuncDeclaration::semantic3.
...
else if (hasReturnExp & 8) // if inline asm
{
flags &= ~FUNCFLAGnothrowInprocess;
}
else
{
// Check for errors related to 'nothrow'.
unsigned int nothrowErrors = global.errors;
int blockexit = fbody->blockExit(this, f->isnothrow);
if (f->isnothrow && (global.errors != nothrowErrors) )
::error(loc, "%s '%s' is nothrow yet may throw", kind(), toPrettyChars());
...
In front-end, if a function body has inline asm statements, the function's nothrow check is skipped! But many functions in druntime rely on the loose behavior currently.