diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index f6a07b8e01f..5798d7d5ca3 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -105,8 +105,10 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting usage.usedOtherFile = true; } - if (!usage.lineNumber) + if (!usage.lineNumber) { usage.lineNumber = func->token->linenr(); + usage.column = func->token->column(); + } usage.isC = func->token->isC(); usage.isStatic = func->isStatic(); @@ -341,13 +343,14 @@ static bool isOperatorFunction(const std::string & funcName) static void staticFunctionError(ErrorLogger& errorLogger, const std::string &filename, - unsigned int fileIndex, - unsigned int lineNumber, + nonneg int fileIndex, + nonneg int lineNumber, + nonneg int column, const std::string &funcname) { std::list locationList; if (!filename.empty()) { - locationList.emplace_back(filename, lineNumber, 0); + locationList.emplace_back(filename, lineNumber, column); locationList.back().fileIndex = fileIndex; } @@ -366,7 +369,8 @@ bool CheckUnusedFunctions::check(const Settings& settings, ErrorLogger& errorLog { logChecker("CheckUnusedFunctions::check"); // unusedFunction - using ErrorParams = std::tuple; + // filename, fileindex, line, column + using ErrorParams = std::tuple; std::vector errors; // ensure well-defined order std::vector staticFunctionErrors; @@ -382,33 +386,33 @@ bool CheckUnusedFunctions::check(const Settings& settings, ErrorLogger& errorLog std::string filename; if (func.filename != "+") filename = func.filename; - errors.emplace_back(filename, func.fileIndex, func.lineNumber, it->first); + errors.emplace_back(filename, func.fileIndex, func.lineNumber, func.column, it->first); } else if (func.isC && !func.isStatic && !func.usedOtherFile) { std::string filename; if (func.filename != "+") filename = func.filename; - staticFunctionErrors.emplace_back(filename, func.fileIndex, func.lineNumber, it->first); + staticFunctionErrors.emplace_back(filename, func.fileIndex, func.lineNumber, func.column, it->first); } } std::sort(errors.begin(), errors.end()); for (const auto& e : errors) - unusedFunctionError(errorLogger, std::get<0>(e), std::get<1>(e), std::get<2>(e), std::get<3>(e)); + unusedFunctionError(errorLogger, std::get<0>(e), std::get<1>(e), std::get<2>(e), std::get<3>(e), std::get<4>(e)); std::sort(staticFunctionErrors.begin(), staticFunctionErrors.end()); for (const auto& e : staticFunctionErrors) - staticFunctionError(errorLogger, std::get<0>(e), std::get<1>(e), std::get<2>(e), std::get<3>(e)); + staticFunctionError(errorLogger, std::get<0>(e), std::get<1>(e), std::get<2>(e), std::get<3>(e), std::get<4>(e)); return !errors.empty(); } void CheckUnusedFunctions::unusedFunctionError(ErrorLogger& errorLogger, - const std::string &filename, unsigned int fileIndex, unsigned int lineNumber, + const std::string &filename, nonneg int fileIndex, nonneg int lineNumber, nonneg int column, const std::string &funcname) { std::list locationList; if (!filename.empty()) { - locationList.emplace_back(filename, lineNumber, 0); + locationList.emplace_back(filename, lineNumber, column); locationList.back().fileIndex = fileIndex; } @@ -417,7 +421,10 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger& errorLogger, } CheckUnusedFunctions::FunctionDecl::FunctionDecl(const Function *f) - : functionName(f->name()), fileIndex(f->token->fileIndex()), lineNumber(f->token->linenr()) + : functionName(f->name()) + , fileIndex(f->token->fileIndex()) + , lineNumber(f->token->linenr()) + , column(f->token->column()) {} std::string CheckUnusedFunctions::analyzerInfo(const Tokenizer &tokenizer) const @@ -427,7 +434,9 @@ std::string CheckUnusedFunctions::analyzerInfo(const Tokenizer &tokenizer) const ret << " \n"; + << " lineNumber=\"" << functionDecl.lineNumber << '\"' + << " column=\"" << functionDecl.column << '\"' + << "/>\n"; } for (const std::string &fc : mFunctionCalls) { ret << " \n"; @@ -437,13 +446,15 @@ std::string CheckUnusedFunctions::analyzerInfo(const Tokenizer &tokenizer) const namespace { struct Location { - Location() : lineNumber(0) {} - Location(std::string f, const int l) : fileName(std::move(f)), lineNumber(l) {} + Location() : lineNumber(0), column(0) {} + Location(std::string f, nonneg int l, nonneg int c) : fileName(std::move(f)), lineNumber(l), column(c) {} std::string fileName; - int lineNumber; + nonneg int lineNumber; + nonneg int column; }; } +// TODO: bail out on unexpected data void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLogger &errorLogger, const std::string &buildDir) { std::map decls; @@ -490,8 +501,9 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo const char* lineNumber = e2->Attribute("lineNumber"); if (lineNumber) { const char* file = e2->Attribute("file"); + const char* column = default_if_null(e2->Attribute("column"), "0"); // cppcheck-suppress templateInstantiation - TODO: fix this - see #11631 - decls[functionName] = Location(file ? file : sourcefile, strToInt(lineNumber)); + decls[functionName] = Location(file ? file : sourcefile, strToInt(lineNumber), strToInt(column)); } } } @@ -506,7 +518,7 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo if (calls.find(functionName) == calls.end() && !isOperatorFunction(functionName)) { const Location &loc = decl->second; - unusedFunctionError(errorLogger, loc.fileName, /*fileIndex*/ 0, loc.lineNumber, functionName); + unusedFunctionError(errorLogger, loc.fileName, /*fileIndex*/ 0, loc.lineNumber, loc.column, functionName); } } } @@ -516,8 +528,10 @@ void CheckUnusedFunctions::updateFunctionData(const CheckUnusedFunctions& check) for (const auto& entry : check.mFunctions) { FunctionUsage &usage = mFunctions[entry.first]; - if (!usage.lineNumber) + if (!usage.lineNumber) { usage.lineNumber = entry.second.lineNumber; + usage.column = entry.second.column; + } // TODO: why always overwrite this but not the filename and line? usage.fileIndex = entry.second.fileIndex; if (usage.filename.empty()) diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 69b7cf2fc88..b835b505ebd 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -57,7 +57,7 @@ class CPPCHECKLIB CheckUnusedFunctions { static void analyseWholeProgram(const Settings &settings, ErrorLogger& errorLogger, const std::string &buildDir); static void getErrorMessages(ErrorLogger &errorLogger) { - unusedFunctionError(errorLogger, "", 0, 0, "funcName"); + unusedFunctionError(errorLogger, "", 0, 0, 0, "funcName"); } // Return true if an error is reported. @@ -67,13 +67,14 @@ class CPPCHECKLIB CheckUnusedFunctions { private: static void unusedFunctionError(ErrorLogger& errorLogger, - const std::string &filename, unsigned int fileIndex, unsigned int lineNumber, + const std::string &filename, nonneg int fileIndex, nonneg int lineNumber, nonneg int column, const std::string &funcname); struct CPPCHECKLIB FunctionUsage { std::string filename; - unsigned int lineNumber{}; - unsigned int fileIndex{}; + nonneg int lineNumber{}; + nonneg int column{}; + nonneg int fileIndex{}; bool usedSameFile{}; bool usedOtherFile{}; bool isC{}; @@ -87,7 +88,8 @@ class CPPCHECKLIB CheckUnusedFunctions { explicit FunctionDecl(const Function *f); std::string functionName; nonneg int fileIndex; - unsigned int lineNumber; + nonneg int lineNumber; + nonneg int column; }; std::list mFunctionDecl; std::set mFunctionCalls; diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index ebb182ea08c..a2bf847a2a7 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -135,7 +135,7 @@ def __test_compile_commands_unused_function(tmpdir, use_j): proj_path_sep = os.path.join(__script_dir, 'proj-inline-suppress-unusedFunction') + os.path.sep lines = stderr.splitlines() assert lines == [ - "{}B.cpp:6:0: style: The function 'unusedFunctionTest' is never used. [unusedFunction]".format(proj_path_sep) + "{}B.cpp:6:9: style: The function 'unusedFunctionTest' is never used. [unusedFunction]".format(proj_path_sep) ] assert stdout == '' assert ret == 1, stdout diff --git a/test/cli/other_test.py b/test/cli/other_test.py index b2df1adbc35..6a573579c52 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -858,7 +858,7 @@ class A { args += extra_args _, _, stderr = cppcheck(args) - assert stderr == "{}:4:0: style: The function 'f' is never used. [unusedFunction]\n".format(test_h_file) + assert stderr == "{}:4:26: style: The function 'f' is never used. [unusedFunction]\n".format(test_h_file) def test_unused_function_include(tmpdir): diff --git a/test/cli/qml_test.py b/test/cli/qml_test.py index de4a8d900af..5ce7428b0ae 100644 --- a/test/cli/qml_test.py +++ b/test/cli/qml_test.py @@ -26,9 +26,9 @@ def __test_unused_functions(extra_args): lines.sort() # there are unused functions. But fillSampleData is not unused because that is referenced from main.qml assert lines == [ - "{}samplemodel.cpp:15:0: style: The function 'data' is never used. [unusedFunction]".format(__project_dir_sep), - "{}samplemodel.cpp:38:0: style: The function 'roleNames' is never used. [unusedFunction]".format(__project_dir_sep), - "{}samplemodel.cpp:9:0: style: The function 'rowCount' is never used. [unusedFunction]".format(__project_dir_sep) + "{}samplemodel.cpp:15:23: style: The function 'data' is never used. [unusedFunction]".format(__project_dir_sep), + "{}samplemodel.cpp:38:37: style: The function 'roleNames' is never used. [unusedFunction]".format(__project_dir_sep), + "{}samplemodel.cpp:9:18: style: The function 'rowCount' is never used. [unusedFunction]".format(__project_dir_sep) ] assert ret == 0, stdout diff --git a/test/cli/unused_function_test.py b/test/cli/unused_function_test.py index 564becb5bc8..591986f1dde 100644 --- a/test/cli/unused_function_test.py +++ b/test/cli/unused_function_test.py @@ -44,7 +44,7 @@ def __test_unused_functions(extra_args): ret, stdout, stderr = cppcheck(args) assert stdout.splitlines() == [] assert stderr.splitlines() == [ - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) + "{}3.c:3:6: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) ] assert ret == 0, stdout @@ -103,7 +103,7 @@ def __test_unused_functions_project(extra_args): ret, stdout, stderr = cppcheck(args) assert stdout.splitlines() == [] assert [ - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) + "{}3.c:3:6: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) ] == stderr.splitlines() assert ret == 0, stdout @@ -163,7 +163,7 @@ def __test_unused_functions_compdb(tmpdir, extra_args): ret, stdout, stderr = cppcheck(args) assert stdout.splitlines() == [] assert stderr.splitlines() == [ - "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) + "{}3.c:3:6: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) ] assert ret == 0, stdout diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index b705ed91f61..2636ce2db25 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -130,7 +130,7 @@ class TestUnusedFunctions : public TestFixture { " if (f1())\n" " { }\n" "}"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); } void return1() { @@ -138,7 +138,7 @@ class TestUnusedFunctions : public TestFixture { "{\n" " return f1();\n" "}"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); } void return2() { @@ -146,7 +146,7 @@ class TestUnusedFunctions : public TestFixture { "{\n" " return foo();\n" "}"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:8]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); } void return3() { @@ -172,7 +172,7 @@ class TestUnusedFunctions : public TestFixture { "{\n" " void (*f)() = cond ? f1 : NULL;\n" "}"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); } void callback2() { // #8677 @@ -185,7 +185,7 @@ class TestUnusedFunctions : public TestFixture { "void C::callback() {}\n" // <- not unused "\n" "void C::start() { ev.set(this); }"); - ASSERT_EQUALS("[test.cpp:9:0]: (style) The function 'start' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:9]: (style) The function 'start' is never used. [unusedFunction]\n", errout_str()); } void else1() { @@ -194,7 +194,7 @@ class TestUnusedFunctions : public TestFixture { " if (cond) ;\n" " else f1();\n" "}"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'f1' is never used. [unusedFunction]\n", errout_str()); } void functionpointer() { @@ -280,7 +280,7 @@ class TestUnusedFunctions : public TestFixture { "}\n" "\n" "void h() { g(); h(); }"); - ASSERT_EQUALS("[test.cpp:8:0]: (style) The function 'h' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:6]: (style) The function 'h' is never used. [unusedFunction]\n", errout_str()); } void template3() { // #4701 @@ -291,7 +291,7 @@ class TestUnusedFunctions : public TestFixture { " template void foo( T t ) const;\n" "};\n" "template void X::foo( T t ) const { }"); - ASSERT_EQUALS("[test.cpp:3:0]: (style) The function 'bar' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style) The function 'bar' is never used. [unusedFunction]\n", errout_str()); } void template4() { // #9805 @@ -311,7 +311,7 @@ class TestUnusedFunctions : public TestFixture { " test();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:11:0]: (style) The function 'test' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:10]: (style) The function 'test' is never used. [unusedFunction]\n", errout_str()); } void template5() { // #9220 @@ -337,7 +337,7 @@ class TestUnusedFunctions : public TestFixture { check("void f() {\n" " std::array,3> array;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); } void template8() { // #11485 @@ -345,7 +345,7 @@ class TestUnusedFunctions : public TestFixture { " template\n" " void tf(const T&) { }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3:0]: (style) The function 'tf' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style) The function 'tf' is never used. [unusedFunction]\n", errout_str()); check("struct C {\n" " template\n" @@ -407,19 +407,19 @@ class TestUnusedFunctions : public TestFixture { void unusedError() { check("void foo() {}\n" "int main()"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); check("void foo() const {}\n" "int main()"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); check("void foo() const throw() {}\n" "int main()"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); check("void foo() throw() {}\n" "int main()"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); } void unusedMain() { @@ -457,7 +457,7 @@ class TestUnusedFunctions : public TestFixture { void returnRef() { check("int& foo() {return x;}"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\n", errout_str()); } void attribute() { // #3471 - FP __attribute__((constructor)) @@ -556,7 +556,7 @@ class TestUnusedFunctions : public TestFixture { "void f() {\n" " parse(line, blanks_p >> ident[&_xy] >> blanks_p >> eol_p).full;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2:0]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); } void enumValues() { // #11486 @@ -566,8 +566,8 @@ class TestUnusedFunctions : public TestFixture { " void Break() {}\n" " void Break1() {}\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4:0]: (style) The function 'Break' is never used. [unusedFunction]\n" - "[test.cpp:5:0]: (style) The function 'Break1' is never used. [unusedFunction]\n", + ASSERT_EQUALS("[test.cpp:4:10]: (style) The function 'Break' is never used. [unusedFunction]\n" + "[test.cpp:5:10]: (style) The function 'Break1' is never used. [unusedFunction]\n", errout_str()); check("struct S {\n" // #12899 @@ -577,14 +577,14 @@ class TestUnusedFunctions : public TestFixture { "int main() {\n" " E e{ f };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2:0]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); } void recursive() { check("void f() {\n" // #8159 " f();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'f' is never used. [unusedFunction]\n", + ASSERT_EQUALS("[test.cpp:1:6]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); } @@ -605,20 +605,20 @@ class TestUnusedFunctions : public TestFixture { // Check for unused functions.. (c.check)(settings, *this); // TODO: check result - ASSERT_EQUALS("[test1.cpp:1:0]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test1.cpp:1:13]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); } void lineNumber() { check("void foo();\n" "void bar() {}\n" "int main() {}"); - ASSERT_EQUALS("[test.cpp:2:0]: (style) The function 'bar' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: (style) The function 'bar' is never used. [unusedFunction]\n", errout_str()); } void ignore_declaration() { check("void f();\n" "void f() {}"); - ASSERT_EQUALS("[test.cpp:2:0]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); check("void f(void) {}\n" "void (*list[])(void) = {f};"); @@ -689,10 +689,10 @@ class TestUnusedFunctions : public TestFixture { void entrypointsWin() { check("int WinMain() { }"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'WinMain' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function 'WinMain' is never used. [unusedFunction]\n", errout_str()); check("int _tmain() { }"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function '_tmain' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function '_tmain' is never used. [unusedFunction]\n", errout_str()); const Settings s = settingsBuilder(settings).library("windows.cfg").build(); @@ -705,10 +705,10 @@ class TestUnusedFunctions : public TestFixture { void entrypointsWinU() { check("int wWinMain() { }"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function 'wWinMain' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function 'wWinMain' is never used. [unusedFunction]\n", errout_str()); check("int _tmain() { }"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function '_tmain' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function '_tmain' is never used. [unusedFunction]\n", errout_str()); const Settings s = settingsBuilder(settings).library("windows.cfg").build(); @@ -722,8 +722,8 @@ class TestUnusedFunctions : public TestFixture { void entrypointsUnix() { check("int _init() { }\n" "int _fini() { }\n"); - ASSERT_EQUALS("[test.cpp:1:0]: (style) The function '_init' is never used. [unusedFunction]\n" - "[test.cpp:2:0]: (style) The function '_fini' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5]: (style) The function '_init' is never used. [unusedFunction]\n" + "[test.cpp:2:5]: (style) The function '_fini' is never used. [unusedFunction]\n", errout_str()); const Settings s = settingsBuilder(settings).library("gnu.cfg").build(); @@ -744,7 +744,7 @@ class TestUnusedFunctions : public TestFixture { ScopedFile header("test.h", inc); const std::string processed = PreprocessorHelper::getcode(settings, *this, code, "", "test.cpp"); check(processed); - TODO_ASSERT_EQUALS("[test.h:3:0]: (style) The function 'f' is never used. [unusedFunction]\n", "[test.cpp:3:0]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); + TODO_ASSERT_EQUALS("[test.h:3:6]: (style) The function 'f' is never used. [unusedFunction]\n", "[test.cpp:3:6]: (style) The function 'f' is never used. [unusedFunction]\n", errout_str()); } void virtualFunc() @@ -778,7 +778,7 @@ class TestUnusedFunctions : public TestFixture { "int main() {\n" " const int url(0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2:0]: (style) The function 'url' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) The function 'url' is never used. [unusedFunction]\n", errout_str()); } void typeInCast() @@ -790,7 +790,7 @@ class TestUnusedFunctions : public TestFixture { " struct Type {} t;\n" " Type t2{ (Type)t };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2:0]: (style) The function 'Type' is never used. [unusedFunction]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) The function 'Type' is never used. [unusedFunction]\n", errout_str()); } void attributeCleanup() @@ -838,7 +838,7 @@ class TestUnusedFunctions : public TestFixture { "int main() {\n" " f();\n" "}\n", dinit(CheckOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:1:0]: (style) The function 'f' should have static linkage since it is not used outside of its translation unit. [staticFunction]\n", errout_str()); + ASSERT_EQUALS("[test.c:1:6]: (style) The function 'f' should have static linkage since it is not used outside of its translation unit. [staticFunction]\n", errout_str()); } };