C compilers (and by extension C++ compilers) usually have an extension which allows a function to be marked as one that never returns. The point of this is it enables improved data flow analysis and better code being generated.

Noreturn functions crop up in things like assert's and enforce's. DMD internally hardcodes a few functions it knows about that are noreturn, and the DMD optimizer and codegen take advantage of it.

But when people write their own assert's and enforce's, this falls apart. While the programs will still work, they won't be as efficient as they could be.

Having an @noreturn attribute will take care of that:

   @noreturn void ThisFunctionExits();

Yes, it's another builtin attribute and attributes are arguably a failure in language design.

Has anyone a better idea? Does anyone want to write a DIP for this?

Example:

DMC uses a pragma to do it:

    void ThisFunctionExits();
    #pragma noreturn(ThisFunctionExits);

GCC uses an attribute:

    void ThisFunctionExits() __attribute__ ((__noreturn__));

VC uses:

    __declspec(noreturn) void ThisFunctionExits();

Reply via email to