Hi Martin,

> +void foo(void*);
> +void bar()
> +{
> +     foo(0);                         /* { dg-warning "zero as null pointer 
> constant" } */
> +     foo(NULL);
> +
> +     void *p = 0;                    /* { dg-warning "zero as null pointer 
> constant" } */
> +     void *r = NULL;
> +     void *q = { 0 };                /* { dg-warning "zero as null pointer 
> constant" } */
> +     void *s = { NULL };
> +     struct { void *q; } x = { 0 };  /* { dg-warning "zero as null pointer 
> constant" } */
> +     struct { void *q; } y = { NULL };
> +
> +     1 ? 0 : p;                      /* { dg-warning "zero as null pointer 
> constant" } */
> +     1 ? p : 0;                      /* { dg-warning "zero as null pointer 
> constant" } */
> +     1 ? 0 : NULL;                   /* { dg-warning "zero as null pointer 
> constant" } */
> +     1 ? NULL : 0;                   /* { dg-warning "zero as null pointer 
> constant" } */
> +
> +     if (p == 0);                    /* { dg-warning "zero as null pointer 
> constant" } */
> +     if (0 == p);                    /* { dg-warning "zero as null pointer 
> constant" } */
> +     if (NULL == 0);                 /* { dg-warning "zero as null pointer 
> constant" } */
> +     if (0 == NULL);                 /* { dg-warning "zero as null pointer 
> constant" } */
> +     if (0 == nullptr);              /* { dg-warning "zero as null pointer 
> constant" } */
> +     if (nullptr == 0);              /* { dg-warning "zero as null pointer 
> constant" } */
> +}

I'm thinking that it may be good to add some tests to check that structs
with implicit initialization to 0s don't trigger this diagnostic.

        struct ( int a; void *b; } a = { 0 };
        struct ( int a; int b; void *b; } b = { 0 , 0 };

There might be other corner cases worth testing.

Thanks for adding this diagnostic!  Feel free to add:

Suggested-by: Alejandro Colomar <a...@kernel.org>
Acked-by: Alejandro Colomar <a...@kernel.org>

Cheers,
Alex


-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature

Reply via email to