]> granicus.if.org Git - clang/commitdiff
Don't have side-effects (or rather non-trivial computation) in StringSwitch "cases."
authorTed Kremenek <kremenek@apple.com>
Sat, 12 Mar 2011 04:08:07 +0000 (04:08 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 12 Mar 2011 04:08:07 +0000 (04:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127528 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp

index add9751d652283cdeb5b45290afa1ddb749aa5c9..1925131632bf1f04e950321ce11ec5629db5bab9 100644 (file)
@@ -282,12 +282,15 @@ const GRState *IteratorsChecker::handleAssign(const GRState *state,
       // Finally, see if it is one of the calls that will create
       // a valid iterator and mark it if so, else mark as Unknown.
       llvm::StringRef mName = ME->getMemberDecl()->getName();
-      return llvm::StringSwitch<const GRState*>(mName)
-        .Cases("begin", "insert", "erase",
-               state->set<IteratorState>(MR, RefState::getBeginValid(IMR)))
-        .Case("end",
-              state->set<IteratorState>(MR, RefState::getEndValid(IMR)))
-        .Default(state->set<IteratorState>(MR, RefState::getUnknown()));      
+      
+      if (llvm::StringSwitch<bool>(mName)        
+          .Cases("begin", "insert", "erase", true).Default(false)) {
+        return state->set<IteratorState>(MR, RefState::getBeginValid(IMR));
+      }
+      if (mName == "end")
+        return state->set<IteratorState>(MR, RefState::getEndValid(IMR));
+
+      return state->set<IteratorState>(MR, RefState::getUnknown());
     }
   }
   // Handle straight copy from another iterator.