[cfe-dev] RFC: clang-tidy readability-else-after-return: what about continue/break in loops?
David Blaikie via cfe-dev
cfe-dev at lists.llvm.org
Fri Jan 15 12:55:51 PST 2016
On Fri, Jan 15, 2016 at 12:15 PM, Richard via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> [Please reply *only* to the list and do not include my email directly
> in the To: or Cc: of your reply; otherwise I will not see your reply.
> Thanks.]
>
> Hi,
>
> Clang-tidy's readability-else-after-return flags constructs such as:
>
> if (foo) {
> return;
> } else {
> other_stuff();
> }
>
> Since there's no way you can both take the 'if (foo)' branch and the
> 'else' branch due to the return statement.
>
> What about similar uses of continue?
>
> for (auto item : container) {
> if (foo) {
> continue;
> } else {
> other_stuff();
> }
> }
>
> Here the continue statement has the same effect locally within the
> for loop as the return statement had in an enclosing function. In
> other words, the following code is equivalent:
>
> for (auto item : container) {
> if (foo) {
> continue;
> }
> other_stuff();
> }
>
> Doesn't a similar situation occur with a break statement in a loop?
>
Yep. throw as well. (or a call to a noreturn function? Probably) Anything
that terminates normal control flow.
> --
> "The Direct3D Graphics Pipeline" free book <
> http://tinyurl.com/d3d-pipeline>
> The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
> The Terminals Wiki <http://terminals.classiccmp.org>
> Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160115/6cb45696/attachment.html>
More information about the cfe-dev
mailing list