assert(false)

Steven Schveighoffer schveiguy at yahoo.com
Fri Jun 21 08:26:34 PDT 2013


On Thu, 20 Jun 2013 15:48:38 -0400, Joseph Rushton Wakeling  
<joseph.wakeling at webdrake.net> wrote:

> Is it considered good/recommended practice to insert an assert(false)  
> statement
> in parts of the code that should be unreachable?  Or simply an optional  
> choice
> that may be useful for debugging?

I think it's more than good practice, the compiler may require it if it  
cannot prove via flow analysis that you are not forgetting to return a  
value.

Note that assert(false) can make the compiler generate code differently,  
if the compiler can prove the function never returns.  I'm more fuzzy on  
this detail.

-Steve


More information about the Digitalmars-d-learn mailing list