<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>Hi Rémi,</p>
<p>First of all I would like to apologize for trying to stand my ground so firmly when the, as it turns out, expressed opinion is <strong>not</strong> accurate.</p>
<p>I am truly sorry.</p>
<p>On 2017-02-27 18:47, Rémi Denis-Courmont wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> As I tried to explain, error and warning attributes will not work if the 
 function is inlined. Function call attributes do not apply if the function is 
 not called. This is how GCC decided to implement that GCC extension. Sure, it 
 would be easier another way. But I do not get to decide how GCC designs and 
 implements their extensions, and neither do you.</code></pre>
</blockquote>
<p>Yes, you are indeed correct - and below I will elaborate on my reasoning and show other readers where/why I ended up with the wrong conclusion (because it is somewhat interesting).</p>
<p>All the best,<br />
Filip (now a little wiser) Roséen</p>
<h3 id="the-faulty-experiment">The faulty experiment</h3>
<pre><code>#ifdef NOINLINE
__attribute__((noinline))
#endif
__attribute__((error(""))) int foo() { return 0; }

int main()
{
#ifdef DEADCODE
    return 0; foo();
#else
    return foo();
#endif
}</code></pre>
<p>I tried the above snippet with a bunch of different versions of <code>gcc</code>, and toggled <code>-DNOINLINE</code> with <code>-DDEADCODE</code> in order to try all the combinations.</p>
<p>Not only did the behavior change between versions, the result did not depend on whether <code>__attribute__((noinline))</code> was applied:</p>
<ul>
<li><p>The <em>error-diagnostic</em> appeared for all cases where <code>main</code> returned the result of <code>foo</code>, and;</p></li>
<li><p>did not appear when <code>foo</code> was called in <em>deadcode</em>.</p></li>
</ul>
<h3 id="the-missing-point-why-i-failed-my-tests">The missing point (why I failed my tests)</h3>
<p>As it turns out, unless the <code>-O1</code> (or higher) optimization flag is used, <code>gcc</code> will not decide to inline the call to <code>foo</code>, and the <em>error-diagnostic</em> will be displayed.</p>
<p><em>Rémi Denis-Courmount</em> is, as stated, correct in saying that the <code>noinline</code> attribute is a required entity in order for the relevant code to behave as it should because when compiled with optimization, <code>gcc</code> will inline the call to <code>foo</code> leading to the <em>error-diagnostic</em> not being triggered.</p>
</body>
</html>