title: Calls that precede a function's definition cannot be inlined?
body: <p>The <a href="https://gcc.gnu.org/onlinedocs/gcc/Inline.html" rel="noreferrer">gcc documentation</a> contains the following:</p>
  
  <blockquote>
    <p>When a function is both inline and static, if all calls to the
    function are integrated into the caller, and the function's address is
    never used, then the function's own assembler code is never
    referenced. In this case, GCC does not actually output assembler code
    for the function, unless you specify the option
    -fkeep-inline-functions. Some calls cannot be integrated for various reasons (in particular, <strong>calls that precede the function's definition
    cannot be integrated</strong>, and neither can recursive calls within the
    definition).</p>
  </blockquote>
  
  <p>That always sounded absurd to me -- why would a modern compiler be that dumb? After a quick test it does seem untrue.</p>
  
  <p>The test code:</p>
  
  <pre><code>static inline int foo();
  
  int bar() {
      return foo();
  }
  
  int foo() {
      return 42;
  }
  </code></pre>
  
  <p>The result with gcc-4.9.2 on Linux contains code for <code>bar()</code> but none for <code>foo()</code>. You can see that <code>foo()</code> has been integrated:</p>
  
  <pre><code>bar:
  .LFB0:
      .cfi_startproc
      movl    $42, %eax
      ret
      .cfi_endproc
  </code></pre>
  
  <p>If I compile as C++ the result is the same, except for name mangling.</p>
  
  <p>Contrary to the documentation, despite <code>foo()</code> being defined after the call in <code>bar()</code>, <code>foo()</code> has been completely integrated into <code>bar()</code>.</p>
  
  <p>Do I misunderstand the documentation or is it incorrect? Perhaps it's correct for some more complicated case?</p>
  
  <p>I don't know if there's a technical distinction between "integrate" and "inline" but I suspect "integrate" is being used to distinguish from keyword <code>inline</code> and it just refers to function inlining (hence the title).</p>
  
  <p>This question is tagged as C and C++ because this portion of the gcc documentation pertains to the "C language family" and I expect the answer to be the same for the two languages.</p>