[swift-evolution] Disallowing unreachable code

Peter Dillinger Peter.Dillinger at synopsys.com
Mon Mar 27 12:32:48 CDT 2017

I should have clarified what I mean by "unreachable".  I am referring to user code that is orphaned in a standard control flow graph construction, which does not perform any optimizations based on the values of expressions.  The following has unreachable code:

  return 42;
  return -1; // unreachable

The following does not (from the blog post: "use 'if (false)' all you want"):

  if (false) {
    return -1;

And the following, which allows you to bypass an existing function definition does not:

  if (true) {
    return -1;

We call that "dead code" and in particular "intentional" because it's obvious from how it's written that the programmer intended to disable some code.  The reason for disallowing unreachable code is that it's too easy get accidentally, which also makes the intent unclear.

Peter Dillinger, Ph.D.
Software Engineering Manager, Coverity Analysis, Software Integrity Group | Synopsys

More information about the swift-evolution mailing list