Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It certainly seems possible if you avoid pointer to functions (and deem them unsafe) by using the ABT of the program. Clang's AST is (despite its name) such an ABT: you will see both declarations and definitions of the functions. By doing your work one definition at a time, you will already have a good baseline.</p> <p>On the other hand, I wonder whether this is <em>practical</em>. See, the problem is that any function performing a memory allocation is (voluntarily) marked as potentially throwing (because <code>new</code> never returns null, but throws <code>bad_alloc</code> instead). Therefore, your <code>noexcept</code> will be limited to a handful of functions in most cases.</p> <p>And of course there are all the dynamic conditions like @GManNickG exposed, for example:</p> <pre><code>void foo(boost::optional&lt;T&gt; const t&amp;) { if (not t) { return; } t-&gt;bar(); } </code></pre> <p>Even if <code>T::bar</code> is <code>noexcept</code>, dereferencing an <code>optional&lt;T&gt;</code> may throw (if there is nothing). Of course, this ignores the fact that we already ruled this out (here).</p> <p>Without having clear <em>conditions</em> on when a function might <code>throw</code>, <code>static</code> analysis might prove... useless. The language idioms are designed with exceptions in mind.</p> <hr> <p><em>Note: as a digression, the optional class could be rewritten so as not to exposed dereferencing, and thus be <code>noexcept</code> (if the callbacks are):</em></p> <pre><code>template &lt;typename T&gt; class maybe { public: template &lt;typename OnNone, typename OnJust&gt; void act(OnNone&amp;&amp; n, OnJust&amp;&amp; j) noexcept(noexcept(n()) and noexcept(j(std::declval&lt;T&amp;&gt;()))) { if (not _assigned) { n(); return; } j(*reinterpret_cast&lt;T*&gt;(&amp;_storage)); } private: std::aligned_storage&lt;sizeof(T), alignof(T)&gt;::type _storage; bool _assigned; }; // No idea if this way of expressing the noexcept dependency is actually correct. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload