Re: Minor cleanup after adding more warnings to CFLAGS

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <acqHc8G_BbFartoZ@devuan>
Hi Rene,

On 2026-03-29T17:36:52+0200, Rene Kita wrote:
> On Sun, Mar 29, 2026 at 12:07:31PM +0200, Rene Kita wrote:
> > I had some time and wanted to see how mutt compiles with more warnings
> > enabled, i.e. CFLAGS='-Wall -Wcast-qual -Werror
> > -Wimplicit-function-declaration -Wimplicit-int -Wnull-dereference
> > -Wold-style-definition -Wredundant-decls -Wstrict-prototypes
> > -Wstring-compare -Wtype-limits -Wuninitialized -Wunused'
> > 
> > Turns out there's a lot the compiler complains about, especially when it
> > comes to some const usage. The following patches are a result of this
> > experiment and are far from a complete fix.
> > 
> > This series depends on the proposed reformatting from Kevin. It's
> > untested besides compilation and CI.
> 
> Below is the shortened build log with the remaining errors after my 9
> patches were applied. Adding more const to avoid these errors leads to
> more errors somewhere else in the call chain. There are other errors
> which come from -Wtype-limits and -Wredundant-decls.
> 
> Most prominent example is imap_next_word which is called in a lot of
> functions taking const char * as an parameter. We do cast away the const
> there. imap_next_word does not modify the string, but will return the
> string in the end. This means if we let imap_next_word take a const
> char * we also need to return a const char *. But this does not work
> everywhere it is used.
> 
> What is the general opinion here regarding such compiler flags and how
> to handle such situations?
> 
> For me -Wcast-qual is one of the most important flags. I prefer to use
> less const if needed to make the build pass without warnings.
> Suppressing warnings should only be used when interacting with
> interfaces not under our control.

+1.

I love this patch set.


Have a lovely day!
Alex

> 
> --
> 
> [...]
> command.c: In function ‘imap_cmd_trailer’:
> command.c:224:22: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>   224 |   s = imap_next_word((char *)s);
>       |                      ^
> command.c:233:22: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>   233 |   s = imap_next_word((char *)s);
>       |                      ^
> command.c: In function ‘cmd_status’:
> command.c:465:22: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>   465 |   s = imap_next_word((char*)s);
>       |                      ^
> command.c: In function ‘cmd_parse_myrights’:
> command.c:1038:22: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>  1038 |   s = imap_next_word((char*)s);
>       |                      ^
> command.c:1039:22: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>  1039 |   s = imap_next_word((char*)s);
>       |                      ^
> command.c: In function ‘cmd_parse_search’:
> command.c:1106:30: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>  1106 |   while ((s = imap_next_word((char*)s)) && *s != '\0')
>       |                              ^
> command.c: In function ‘cmd_parse_enabled’:
> command.c:1293:30: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>  1293 |   while ((s = imap_next_word((char*)s)) && *s != '\0')
>       |                              ^
> [...]
> mutt_socket.c: In function ‘mutt_conn_find’:
> mutt_socket.c:311:22: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>   311 |   mutt_account_tourl((ACCOUNT*) account, &url, 0);
>       |                      ^
> mutt_zstrm.c: In function ‘mutt_zstrm_write’:
> mutt_zstrm.c:190:27: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>   190 |   zctx->write.z.next_in = (Bytef*) buf;
>       |                           ^
> [...]
> pgppubring.c: In function ‘main’:
> pgppubring.c:159:34: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
>   159 |   pgpring_find_candidates(kring, (const char**) argv + optind, argc - optind);
>       |                                  ^
> [...]
> date.c: In function ‘mutt_mktime’:
> date.c:88:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>    88 |   if ((time_t)year > TM_YEAR_MAX)
>       |                    ^
> [...]
> sendlib.c:73:15: warning: redundant redeclaration of ‘environ’ [-Wredundant-decls]
>    73 | extern char **environ;
>       |               ^~~~~~~
> In file included from mutt.h:25,
>                  from sendlib.c:26:
> /usr/include/unistd.h:566:15: note: previous declaration of ‘environ’ with type ‘char **’
>   566 | extern char **environ;
>       |               ^~~~~~~
> sendlib.c: In function ‘convert_file_from_to’:
> sendlib.c:864:50: warning: to be safe all intermediate pointers in cast from ‘char **’ to ‘const char **’ must be ‘const’ qualified [-Wcast-qual]
>   864 |       ret = convert_file_to(file, fcode, ncodes, (const char **)tcode,
>       |                                                  ^
> sendlib.c:879:52: warning: to be safe all intermediate pointers in cast from ‘char **’ to ‘const char **’ must be ‘const’ qualified [-Wcast-qual]
>   879 |     ret = convert_file_to(file, fromcodes, ncodes, (const char **)tcode,
>       |                                                    ^

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmnKh5wACgkQ64mZXMKQ
wqnpARAAlOGu6+geMsycpRBRjoPQSllPBHoFj84292fs1Cdu3EDKOFe5qxNV4cEK
PwytZ4DTvp/3/1VrIWpY7XdLSuaJtGFR6Z9JqNVZXoJjjkYnqzH80if3vcNXKij7
kf8Q/LBZ/JDe6Z/usb7moqDD9yyKZ5WdqarebENLzTySeQcatP5IjOvTfJ2G8PoY
TFE8Hyrve4Kl83TFf940PN0Wkq5EUgNAMSj4zOITKJDeoj3+C823EPB2PY5EQRK1
Vfe2DQdLfCLZfJUXSAclhqTALro9Bl5PsuYGRb+m+EVh86ZgoH2sI9qcDX2VFDE9
cJkY3rcZVyAYhek0zsWx1vyROldc+Q0PjVvkTcAe+9KaVZgOjMyXWdvTodczyN/g
bOa9Ia2/9jJuB0M2QyHLlc0Kbkzwn0XIJHkA7srdPg9X+yEQgCBB89RccpHiW6f2
lkXtlMGc8Ui/XigwvdBEzERsL/JfOqooeCnGZL3shqjEfoxHRHsvtmmJuoEteZKZ
eupczh8bqTrLbrsKCS9IcOaJQr0+6+lFFejPXZrMvhylPTN8P/jGwGNGxERj7cy+
gESnm+pObWqBRlSDP9Us/rWRPo1ND3HyyRakXFEPyfnFMW2wItbfGZtS2Yt8VskH
NAAZVEEqz4JsvSdlBvULwVecy/fV1RsBXseu6rJNRije6KOi4aE=
=1/q8
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.