<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Illegal code generated on end of bool function with missing return"
   href="http://llvm.org/bugs/show_bug.cgi?id=18296">18296</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Illegal code generated on end of bool function with missing return
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>amdmi3@amdmi3.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang++ generates illegal code for function returning bool which lacks return
statement.

I know this case is undefined behavior and what compiler does is essentially
legal, but still it would be nice to do something more productive instead of
generating crashing code, like at least emitting an error instead of a warning.

$ cat > test.cc
bool func() {}
int main() {
  func();
  return 0;
}
$ clang++ test.cc -o test
test.cc:1:14: warning: control reaches end of non-void function [-Wreturn-type]
bool func() {}
             ^
1 warning generated.
$ ./test
Illegal instruction

Assembly:

_Z4funcv:                               # @_Z4funcv
    .cfi_startproc
# BB#0:
    pushq    %rbp
.Ltmp2:
    .cfi_def_cfa_offset 16
.Ltmp3:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
.Ltmp4:
    .cfi_def_cfa_register %rbp
    ud2                                    ; <--
.Ltmp5:
    .size    _Z4funcv, .Ltmp5-_Z4funcv
    .cfi_endproc</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>