This revision was automatically updated to reflect the committed changes.
Closed by commit rL354102: [Analysis] -Wunreachable-code shouldn't fire on 
the increment of a foreach loop (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58134/new/

https://reviews.llvm.org/D58134

Files:
  cfe/trunk/lib/Analysis/ReachableCode.cpp
  cfe/trunk/test/SemaCXX/unreachable-code.cpp


Index: cfe/trunk/lib/Analysis/ReachableCode.cpp
===================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp
@@ -631,6 +631,10 @@
     // a for/for-range loop.  This is the block that contains
     // the increment code.
     if (const Stmt *LoopTarget = B->getLoopTarget()) {
+      // The increment on a foreach statement is not written.
+      if (isa<CXXForRangeStmt>(LoopTarget))
+        return;
+
       SourceLocation Loc = LoopTarget->getBeginLoc();
       SourceRange R1(Loc, Loc), R2;
 
Index: cfe/trunk/test/SemaCXX/unreachable-code.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/unreachable-code.cpp
+++ cfe/trunk/test/SemaCXX/unreachable-code.cpp
@@ -52,6 +52,11 @@
   }
 }
 
+void test4() {
+  for (char c : "abc") // no-warning
+    break;
+}
+
 // PR 6130 - Don't warn about bogus unreachable code with throw's and
 // temporary objects.
 class PR6130 {


Index: cfe/trunk/lib/Analysis/ReachableCode.cpp
===================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp
@@ -631,6 +631,10 @@
     // a for/for-range loop.  This is the block that contains
     // the increment code.
     if (const Stmt *LoopTarget = B->getLoopTarget()) {
+      // The increment on a foreach statement is not written.
+      if (isa<CXXForRangeStmt>(LoopTarget))
+        return;
+
       SourceLocation Loc = LoopTarget->getBeginLoc();
       SourceRange R1(Loc, Loc), R2;
 
Index: cfe/trunk/test/SemaCXX/unreachable-code.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/unreachable-code.cpp
+++ cfe/trunk/test/SemaCXX/unreachable-code.cpp
@@ -52,6 +52,11 @@
   }
 }
 
+void test4() {
+  for (char c : "abc") // no-warning
+    break;
+}
+
 // PR 6130 - Don't warn about bogus unreachable code with throw's and
 // temporary objects.
 class PR6130 {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to