diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ff8279d99..2848c0e87 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -132,8 +132,9 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error if (function.find("operator") != std::string::npos) function = "(valueFlow)"; std::list callstack(1, ErrorMessage::FileLocation(tok, &tokenlist)); + const std::string location = Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":"; ErrorMessage errmsg(callstack, tokenlist.getSourceFilePath(), Severity::debug, - Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":" + function + " bailout: " + what, type, Certainty::normal); + (file.empty() ? "" : location) + function + " bailout: " + what, type, Certainty::normal); errorLogger->reportErr(errmsg); } @@ -141,7 +142,7 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error #define bailout(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailout", tokenlist, errorLogger, tok, what) -#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailoutIncompleteVar", tokenlist, errorLogger, tok, what) +#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what) bailoutInternal("valueFlowBailoutIncompleteVar", tokenlist, errorLogger, tok, what, "", 0, __func__) static std::string debugString(const ValueFlow::Value& v) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 184575784..d4d79f412 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -201,13 +201,14 @@ private: (void)simplify; + // TODO: should be handled in a better way // filter out ValueFlow messages.. const std::string debugwarnings = errout.str(); errout.str(""); std::istringstream istr2(debugwarnings); std::string line; while (std::getline(istr2,line)) { - if (line.find("valueflow.cpp") == std::string::npos) + if (line.find("bailout") == std::string::npos) errout << line << "\n"; } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 1239ddbda..bebdd30b3 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -1949,7 +1949,7 @@ private: "( ( int * * * ) global [ 6 ] ) ( \"assoc\" , \"eggdrop\" , 106 , 0 ) ; " "}"; ASSERT_EQUALS(expected, tok(code)); - ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:3]: (debug) valueflow.cpp:1319:valueFlowConditionExpressions bailout: Skipping function due to incomplete variable global\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable global\n", errout.str()); } void simplifyTypedef68() { // ticket #2355 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 5fffaec39..d6b8c13b7 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3129,8 +3129,8 @@ private: // ticket #2991 - segmentation fault check("::y(){x}"); - ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n" - "[test.cpp:1]: (debug) valueflow.cpp:1321:valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n" + "[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout.str()); } void symboldatabase20() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 801897163..ab4ab531d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -459,13 +459,14 @@ private: std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); + // TODO: handle in a better way // filter out ValueFlow messages.. const std::string debugwarnings = errout.str(); errout.str(""); std::istringstream istr2(debugwarnings); std::string line; while (std::getline(istr2,line)) { - if (line.find("valueflow.cpp") == std::string::npos) + if (line.find("bailout") == std::string::npos) errout << line << "\n"; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 542691618..ce8c25b3e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1571,8 +1571,8 @@ private: " x = y;\n" " if (x == 123) {}\n" "}"); - ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n", + ASSERT_EQUALS( + "[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n", errout.str()); } @@ -1695,8 +1695,8 @@ private: bailout("void f(int x) {\n" " y = ((x<0) ? x : ((x==2)?3:4));\n" "}"); - ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n", + ASSERT_EQUALS( + "[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n", errout.str()); bailout("int f(int x) {\n" @@ -1760,8 +1760,8 @@ private: " if (x != 123) { b = x; }\n" " if (x == 123) {}\n" "}"); - ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable b\n", + ASSERT_EQUALS( + "[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable b\n", errout.str()); code = "void f(int x, bool abc) {\n" @@ -1809,8 +1809,8 @@ private: " case 2: if (x==5) {} break;\n" " };\n" "}"); - ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n", + ASSERT_EQUALS( + "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n", errout.str()); bailout("void f(int x, int y) {\n" @@ -1819,8 +1819,8 @@ private: " case 2: if (x==5) {} break;\n" " };\n" "}"); - ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n", + ASSERT_EQUALS( + "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n", errout.str()); } @@ -1832,7 +1832,7 @@ private: " M;\n" "}"); ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" + "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n", errout.str()); @@ -1842,7 +1842,7 @@ private: " FREE(x);\n" "}"); ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" + "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n", errout.str()); } @@ -1856,7 +1856,7 @@ private: " if (x==123){}\n" "}"); ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" + "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" "[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n", errout.str());