The Point of No Return -- bulldozer00

A cute nugget about [[noreturn]]:

The Point of No Return

by bulldozer00

As part of learning the new feature set in C++11, I stumbled upon the weird syntax for the new “attribute” feature: [[ ]]. One of these new C++11 attributes is [[noreturn]]. ...

Add a Comment

Comments are closed.

Comments (1)

1 0

Mats Taraldsvik said on Jul 28, 2013 04:43 AM:

An additional point which I didn't find mentioned: When functions are marked [[noreturn]], tools (not just the code-generating compiler) can use this to emit better diagnostics.

An example is when static analyzers erroneously generate warnings for dereferencing null pointers when a (custom) assert handler is used to ensure this will never happen.


void func(widget* a)
{
my_assert(a != nullptr);
a->apply();
}


By using the [[noreturn]] attribute on my_assert, the static_analyzer would know that a is never dereferenced if it is nullptr.

The Clang Static Analyzer has this behaviour according to its documentation (http://clang-analyzer.llvm.org/annotations.html#custom_assertions).