r224465 - Adding a -Wunused-value warning for expressions with side effects used in an unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case.

Joerg Sonnenberger joerg at britannica.bec.de
Tue Dec 23 08:01:07 PST 2014


On Wed, Dec 17, 2014 at 09:57:17PM -0000, Aaron Ballman wrote:
> Author: aaronballman
> Date: Wed Dec 17 15:57:17 2014
> New Revision: 224465
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=224465&view=rev
> Log:
> Adding a -Wunused-value warning for expressions with side effects used
> in an unevaluated expression context, such as sizeof(), or decltype().

I think in the case of sizeof, it is too aggressive. It triggered in
NetBSD's mount on logic like the following:

	char ** volatile argv;

	argv = calloc(count, sizeof(*argv));

because the volatile marker supposed makes the *argv have side effects.
It is present in this case, because the function later on uses vfork and
GCC complains about trashing local variables for a function that returns
twice. setjmp would be slightly less obscure.

I think it should *not* trigger in this case for two important reasons:

(1) The sizeof use is completely idiomatic.
(2) The only workaround for the warning introduces possible maintainance
costs, as it would require duplicating the type of argv.

A C programmer should know and expect the memory access to not happen.
I would say this is different from the case Aaron gave on IRC about
sizeof(i++). That's a side effect most would expect to still happen.
To keep the number of exceptions small, I propose the relax the warning
to not trigger on dereference of volatile pointers.

Joerg



More information about the cfe-commits mailing list