diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 88624f0c5..4bf0f760a 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -296,6 +296,13 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog break; } } + + // goto label + if (Token::Match(tok2, "[;{}] %var% :")) { + if (settings->debugwarnings) + bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on goto label"); + break; + } } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 7fb5a858f..d06f476ac 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -272,6 +272,15 @@ private: " $if ($x==$123){}\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x, condition is defined in macro\n", errout.str()); + + // bailout: goto label (TODO: handle gotos more intelligently) + bailout("void f(int x) {\n" + " if (x == 123) { goto out; }\n" + " a=x;\n" // <- x is not 123 + "out:" + " if (x==123){}\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on goto label\n", errout.str()); } void valueFlowForLoop() {