* Bruno Haible:

> Also, if that's the intent of the syntax, it has been overlooked by the
> GCC developers. See:
>
> ============================ decl.c ============================
> #include <stddef.h>
>
> extern void foo1 (double x [static 1]);
> extern void foo2 (double x []) __attribute__ ((__nonnull__(1)));
>
> int bar ()
> {
>   foo1 (NULL);
>   foo2 (NULL);
>   return 1;
> }
> =================================================================
> $ gcc -Wall -S decl.c
> decl.c: In function 'bar':
> decl.c:9:3: warning: null argument where non-null required (argument 1) 
> [-Wnonnull]
>     9 |   foo2 (NULL);
>       |   ^~~~
>
> (This is with gcc 10.1.0.)
>
> clang, OTOH, produces warnings for both foo1 and foo2.
>
> But I won't spend time to report a GCC bug on this, because - as you said -
> without the ability to declare a pointer to an incomplete type or a 'void *'
> as non-null, this language feature is worthless.

It's also undefined when you pass the address of something that is not
the first element of an array of type double to foo1.  (Undefined in the
sense that the standard does not say what happens in that case.)

Thanks,
Florian


Reply via email to