[cfe-commits] [PATCH][PR11329][v14] Generalize -Wempty-body: warn when statement body is empty

Richard Smith richard at metafoo.co.uk
Thu Feb 9 15:56:25 PST 2012


On Thu, Feb 9, 2012 at 6:17 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> Hello Chandler,
>
> Thank you for the review!
>
> On Thu, Feb 9, 2012 at 11:50 AM, Chandler Carruth <chandlerc at google.com>
> wrote:
> > I think there should be two ways to silence this warning:
> >
> > 1) place the semicolon for the empty statement on its own line, or
> > 2) use empty curly braces.
>
> (1) always works, (2) doesn't work only with range-based for.
>
> > Secondly, we shouldn't warn on all range-based for loops: they can have
> > side-effects the same as for-loops. I think for consistency they should
> use
> > the same rules for silencing the warning.
>
> I agree that range-based for loops technically can be used only for
> side-effects, but that is only possible when iterator's operator++ or
> operator!= have side-effects.
>

That's not quite true. operator* could have a side-effect. begin/end could
have a side-effect. And significantly, the construction of the iteration
variable could have a side-effect.

for (WorkerThreadHandle wth : thingsToProcess) {}

In any case, using different rules for a ';' on its own line versus '{}'
seems questionable.

- Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120209/1b43e91e/attachment.html>


More information about the cfe-commits mailing list