On 4/28/06, Mark Mitchell <[EMAIL PROTECTED]> wrote:
Steven Bosscher wrote:
> The documentation of the nonnull attribute says:
>
> `nonnull (ARG-INDEX, ...)'
> The `nonnull' attribute specifies that some function parameters
> should be non-null pointers. For instance, the declaration:
>
> extern void *
> my_memcpy (void *dest, const void *src, size_t len)
> __attribute__((nonnull (1, 2)));
>
> causes the compiler to check that, in calls to `my_memcpy',
> arguments DEST and SRC are non-null.
>
>
> So do we expect our users to know that they should add 1 to every
> ARG-INDEX they pass? That would make this a documentation bug. Or
> is this a "real" bug in G++, and should the compiler correct the
> ARG-INDEX numbers so that the middle-end doesn't get confused?
I think this is a documentation bug.
OK. Andrew Pinski already pointed out http://gcc.gnu.org/PR1607 as
another example.
(Well, really, I think it's a design bug; the attribute should be
applied to the parameters, rather than to the entire function type, so
that users didn't have to count. In other words, it should be:
void f(__attribute((nonnull)) int *);
But, that's just me being wishful.)
:-)
The reason I think this is a documentation bug is that (a) it's always
been this way, ergo we'd be breaking backwards compatibility to change
it,
OK, Richard G. also mentioned this. I'll prepare a documentation patch.
and (b) some of these kinds of attributes could usefully apply to
the "this" pointer.
That is why I was looking at this. We have http://gcc.gnu.org/PR27336,
and part of the fix could be to make the 'this' pointer always
non-NULL. So far I haven't found anyone who can think of a situation
where 'this' can be NULL...
Thanks,
Gr.
Steven