What's the purpose of -Wbad-function-cast, why does it only apply to the direct return value?
<p>There's a rationale for the warning <a href="https://stackoverflow.com/questions/19306784/what-is-the-purpose-of-gccs-wbad-function-cast">here</a>, but that fails to answer the whole picture. For example the following code triggers the warning:</p>

<pre><code>(int)round(M_PI);
</code></pre>

<p>but on the other hand the following code doesn't:</p>

<pre><code>double d;
(int)(d = round(M_PI));
</code></pre>

<p>this doesn't either:</p>

<pre><code>(int)M_PI;
</code></pre>

<p>the rationale was that you shouldn't convert to int by simply casting, but you should use <code>round</code>, <code>floor</code> or similar function. However using <code>round</code> will still trigger the warning, but as seen above typecasting a constant or assigned variable doesn't.</p>

<p>So if it's that bad to cast from <code>double</code> to <code>int</code>, then why doesn't the warning trigger when you write <code>(int)d</code> or <code>(int)M_PI</code>? In what way is one supposed to circumvent the warning in case you want to convert the return value? Is there a warning that would handle these perilous conversions in a more correct/reasonable way?</p>