]> granicus.if.org Git - clang/commit
[Analysis] -Wunreachable-code shouldn't fire on the increment of a foreach loop
authorSam McCall <sam.mccall@gmail.com>
Fri, 15 Feb 2019 07:16:11 +0000 (07:16 +0000)
committerSam McCall <sam.mccall@gmail.com>
Fri, 15 Feb 2019 07:16:11 +0000 (07:16 +0000)
commitd2921c256fea81ed3622deaaed94b949037742a7
treed0963c6dbf0b0b05080546e291d0e295fed8bcdd
parente8f9fc2658e4ec4912362acd5fa65a256d057301
[Analysis] -Wunreachable-code shouldn't fire on the increment of a foreach loop

Summary:
The idea is that the code here isn't written, so doesn't indicate a bug.
Similar to code expanded from macros.

This means the warning no longer fires on this code:
  for (auto C : collection) {
    process(C);
    return;
  }
  handleEmptyCollection();
Unclear whether this is more often a bug or not in practice, I think it's a
reasonable idiom in some cases.
Either way, if we want to warn on "loop that doesn't loop", I think it should be
a separate warning, and catch `while(1) break;`

Reviewers: ilya-biryukov, ioeric

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58134

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354102 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ReachableCode.cpp
test/SemaCXX/unreachable-code.cpp