This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Couldn't `function(arg[static 3])` imply nonnull and array size in C?
- From: Martin Uecker <uecker at eecs dot berkeley dot edu>
- To: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Thu, 7 May 2015 10:51:44 -0700
- Subject: Re: Couldn't `function(arg[static 3])` imply nonnull and array size in C?
- Authentication-results: sourceware.org; auth=none
- References: <CAEcf3Nzxt=uATHYdYu+aLBoKaB8Wyy=AztF=ZXn-atKpKhVU3Q at mail dot gmail dot com> <20150503224039 dot 28ab0404 at lemur> <55479E41 dot 2070108 at gmail dot com>
Am Mon, 04 May 2015 18:28:49 +0200
schrieb Manuel LÃpez-IbÃÃez <lopezibanez@gmail.com>:
> On 04/05/15 07:40, Martin Uecker wrote:
> >
> > BTW: Why is 'nonnull' a function attribute and not something
> > which can be attached to pointer types?
>
> I think this is something wanted for a long time:
>
> https://gcc.gnu.org/ml/gcc/2006-04/msg00550.html
>
> but nobody has implemented it yet. Perhaps there was some technical hurdle in
> the past, probably long gone.
>
> Clang has implemented this variation already sometime ago:
>
> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140203/098497.html
>
> so there is a precedent.
Interestingly, this leads to an incompatibility between gcc and
clang. Consider this:
void foo(__attribute__((nonnull)) int *a)
{
}
void bar(__attribute__((nonnull)) int (*a)(int*))
{
(*a)(0);
}
void test(void)
{
foo(0);
bar(0);
}
clang warns when calling 'foo' and 'bar' with 0 argument.
gcc ignores nonnull on the argument of foo and warns about
calling *a.
Martin