This is the mail archive of the
mailing list for the GCC project.
Re: Couldn't `function(arg[static 3])` imply nonnull and array size in C?
- From: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- To: Martin Uecker <uecker at eecs dot berkeley dot edu>
- Cc: GCC Development <gcc at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Fri, 8 May 2015 10:14:38 +0200
- 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> <20150507105144 dot 277cc59b at lemur>
On 7 May 2015 at 19:51, Martin Uecker <firstname.lastname@example.org> wrote:
> Am Mon, 04 May 2015 18:28:49 +0200
> schrieb Manuel LÃpez-IbÃÃez <email@example.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:
>> 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:
>> so there is a precedent.
> Interestingly, this leads to an incompatibility between gcc and
> clang. Consider this:
> void foo(__attribute__((nonnull)) int *a)
Perhaps this applies?
"At present, the first parameter in a function prototype must have
some type specifier that is not an attribute specifier; this resolves
an ambiguity in the interpretation of void f(int (__attribute__((foo))
But I don't understand the example given in the docs.
In any case, what would be the syntax (in Clang) for specifying that
'*a' is a nonnull function? Clang also implements the gnu-style
nonnull attribute, hence they probably have some incompatibility with
previous versions of itself (the new syntax is only one year old).
In general, my impression (Jason, Joseph, please correct me if I'm
wrong here) is that it is ok to accept attributes in a place that was
ignored previously, and to ignore attributes if the placement was
working by luck and not documented (hopefully with a warning, which we
are missing above?), but it is definitely not ok to ignore attributes
that were documented to work before. It is definitely a goal to make
the placement consistent between C and C++ and to satisfy the rules of
C++ as to where the attributes can appear (but being permissive as to
where they cannot appear). Thus, any testcases that you add should go
to testsuite/c-c++-common unless they are testing C-only or C++-only