[ccan] [PATCH] list: fix -Wcast-qual warnings

Rusty Russell rusty at rustcorp.com.au
Mon May 26 13:51:35 EST 2014


Eric Wong <normalperson at yhbt.net> writes:
> These warnings were encountered when adding ccan/list to cmogstored
> (which uses -Wcast-qual).  This changes the public API for checking,
> but I doubt anybody is affected.

I hate -Wcast-qual; it's a terrible warning.

There are genuine reasons to cast away const in C, and if -Wcast-qual
only warned about casts which changed *more* than the constness it might
be useful.  But it doesn't.

Unfortunately the list_check* functions cast away const so you can use
them to pass through both const and non-const lists (just like
"strchr()").

The correct fix is:
(1) Add a test to show why this has to cast away const.
(2) Use ccan/cast which supports this.
(3) Run ccanlint -v --cflags="-g3 -ggdb -Wall -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1 -Wcast-qual"
    to see what breaks.

There's one wrinkle: ccan/cast is LGPL.  I'm the main author, so I've
just pinged the only other contributor to check it's OK to relicense.

Expect commits soon...

Thanks!
Rusty.


More information about the ccan mailing list