RFE: Add G_GNUC_NONNULL for __attribute__((nonnull))
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. If the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. The compiler may also choose to make optimizations based on the knowledge that certain function arguments will never be null.
If no argument index list is given to the nonnull attribute, all pointer arguments are marked as non-null. To illustrate, the following declaration is equivalent to the previous example:
extern void * my_memcpy (void *dest, const void *src, size_t len) __attribute__((nonnull));
Given that GLib is used by quite some projects as a "C stdlib", I think it would be nice to have some compile-time warnings if you're make a mistake.
That being said, it does add quite some noise if you put it everywhere, and I'm not a fan of the placement of the attrubute
So I'm making this issue if this is something that:
- GLib could/should expose as a G_GNUC_... macro
- GLib could/should annotate on its functions