title: Defining a function returning incompatible type, but unreachable
body: <p>After reading through the C99 standard, I could not find any sections which would forbid defining function <code>f</code> below:</p>
  <pre><code>struct s { double d; };
  
  int f() {
    if (0) return (struct s){.d = 3.14};
    // There is intentionally no return statement of type int, which is valid
  }
  
  int main() {
    f();
    return 0;
  }
  </code></pre>
  <p>In particular, this program's behavior should be defined, since the return value is (a) never reached in the first place and (b) never used, even if it were reached.</p>
  <p>Still, most of my compilers (GCC, Clang and CompCert) prevent this program from being compiled, with error <code>returning 'struct s' from a function with incompatible result type 'int'</code>. I did manage to compile it with <code>tcc</code>, but I don't know if it's mostly due to luck (i.e. lack of verifications).</p>
  <p>Could someone please confirm if this program is syntactically C99 valid, and also that its behavior is completely well-defined, or otherwise indicate where the standard forbids it?</p>
  <p>I actually prefer that my compilers reject it, but for instance some macro definitions could produce code similar to this one, so it could be actually useful to accept such programs if they are valid.</p>
  <p><strong>Background</strong></p>
  <p>Below are the possibly relevant excerpts of the C99 standard that I could find, along with my reasoning on why they should not forbid my program from being syntactically valid and semantically well-defined:</p>
  <blockquote>
  <p><strong>§6.8.6.4</strong> The return statement</p>
  <p><strong>§6.8.6.4.1</strong> A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.</p>
  </blockquote>
  <p>In my code, we have a non-<code>void</code> function with a non-<code>void</code> return, so everything seems fine.</p>
  <blockquote>
  <p><strong>§6.8.6.4.3</strong> If a return statement with an expression is executed, the value of the expression is returned to the caller as the value of the function call expression. If the expression has a type different from the return type of the function in which it appears, the value is converted as if by assignment to an object having the return type of the function.</p>
  </blockquote>
  <p>Because the return statement is never executed, the above does not apply.</p>
  <blockquote>
  <p><strong>§6.9.1</strong> Function definitions</p>
  <p><strong>§6.9.1.12</strong> If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.</p>
  </blockquote>
  <p>The result of the function call is not used by the caller, so the behavior should be defined.</p>