[LLVMbugs] [Bug 18259] New: -Wimplicit-fallthrough gets confused by a non-case label in a switch

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Dec 15 17:17:14 PST 2013


            Bug ID: 18259
           Summary: -Wimplicit-fallthrough gets confused by a non-case
                    label in a switch
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

This doesn't warn but probably should:

Nicos-MacBook-Pro:clang thakis$ cat test3.cc 
int main(int argc, char*argv[]) {
  switch (argc) {
    case 4:
      argc += 4;

Nicos-MacBook-Pro:clang thakis$ ../../Release+Asserts/bin/clang -std=c++11
-Wimplicit-fallthrough test3.cc 

This seems to fix this and not break any other tests as far as I can tell, but
I'm not sure if it's the right fix:

Nicos-MacBook-Pro:clang thakis$ svn diff lib/Sema/AnalysisBasedWarnings.cpp 
Index: lib/Sema/AnalysisBasedWarnings.cpp
--- lib/Sema/AnalysisBasedWarnings.cpp    (revision 197300)
+++ lib/Sema/AnalysisBasedWarnings.cpp    (working copy)
@@ -786,8 +786,12 @@
           continue; // Previous case label has no statements, good.

         const LabelStmt *L = dyn_cast_or_null<LabelStmt>(P->getLabel());
-        if (L && L->getSubStmt() == B.getLabel() && P->begin() == P->end())
-          continue; // Case label is preceded with a normal label, good.
+        if (L && L->getSubStmt() == B.getLabel() && P->begin() == P->end()) {
+          // Case label is preceded by a normal label, keep looking.
+          std::copy(P->pred_begin(), P->pred_end(),
+                    std::back_inserter(BlockQueue));
+          continue;
+        }

         if (!ReachableBlocks.count(P)) {
           for (CFGBlock::const_reverse_iterator ElemIt = P->rbegin(),

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131216/e03f81b2/attachment.html>

More information about the llvm-bugs mailing list