[New-bugs-announce] [issue31338] Use abort() for code we never expect to hit

Barry A. Warsaw report at bugs.python.org
Mon Sep 4 15:18:14 EDT 2017


New submission from Barry A. Warsaw:

Over in bpo-31337 the observation was made that we often use the following pattern in situations we never expect to hit:

assert(0);
return NULL;

but this isn't strictly optimal.  First, the asserts can be compiled away.  Second, it's possible that our assumptions about a particular condition are incorrect.  Third, the intent of non-reachability isn't as clear as it could be.

As suggested in http://bugs.python.org/issue31337#msg301229 it would be better to use

abort() /* NOT REACHED */

instead (although @skrah says "The only drawback is that in the case of libraries, sometimes distribution package lint tools complain." so it would be useful to understand that in more detail.

@serhiy.storchaka says "I have counted 48 occurrences of assert(0), 11 assert(0 && "message") and 2 assert(!"message"). If fix one occurrence, why not fix all others?"  We should!  This issue tracks that.

----------
assignee: barry
components: Interpreter Core
messages: 301244
nosy: barry, serhiy.storchaka, skrah
priority: normal
severity: normal
status: open
title: Use abort() for code we never expect to hit
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31338>
_______________________________________


More information about the New-bugs-announce mailing list