------- Comment #6 from pmoulder at mail dot csse dot monash dot edu dot au 2010-05-12 05:29 ------- Part of the problem is a documentation bug: the nonnull attribute's parameter is named "arg-index", suggesting that the first parameter is 0, while the example strongly suggests that the first parameter is 1.
If parameters are numbered from 1, then please change the name to "arg-number"; if they are numbered from 0, then please change the example to match. On the subject of nonnull's documentation (and only weakly related to the current bug report): To judge from the fact that this attribute is being incorrectly used in glibc on functions like memcmp,memcpy,memmove,qsort etc. where NULL is a valid value (so long as n==0), and also from comments such as at http://chtekk.longitekk.com/index.php?/archives/43-GCCs-__attribute__-nonnull-...-not-helpful-at-all.html, I suggest that the "The compiler may also choose to make optimizations based on the knowledge that certain function arguments will not be null" sentence be given more emphasis: I suggest putting it in a paragraph by itself, and adding a warning that a consequence would be that any checks for NULL in the function will be âoptimized awayâ, and also warning that the attribute is inappropriate for functions such as memcmp,memcpy,memmove,qsort where NULL is only unusual (but valid when n==0) rather than unconditionally invalid. -- pmoulder at mail dot csse dot monash dot edu dot au changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pmoulder at mail dot csse | |dot monash dot edu dot au http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44081