Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,15 +1134,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
codeWithoutCfg = preprocessor.getcode(currentConfig, files, true);
});

if (startsWith(codeWithoutCfg,"#file"))
codeWithoutCfg.insert(0U, "//");
std::string::size_type pos = 0;
while ((pos = codeWithoutCfg.find("\n#file",pos)) != std::string::npos)
codeWithoutCfg.insert(pos+1U, "//");
pos = 0;
while ((pos = codeWithoutCfg.find("\n#endfile",pos)) != std::string::npos)
codeWithoutCfg.insert(pos+1U, "//");
pos = 0;
while ((pos = codeWithoutCfg.find(Preprocessor::macroChar,pos)) != std::string::npos)
codeWithoutCfg[pos] = ' ';
mErrorLogger.reportOut(codeWithoutCfg, Color::Reset);
Expand Down
38 changes: 38 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3853,3 +3853,41 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
]
assert ret == 0, stdout


# The implementation for "A::a" is missing - so don't check if "A::b" is used or not
def test_unused_private_function_incomplete_impl(tmpdir):
test_inc = os.path.join(tmpdir, 'test.h')
with open(test_inc, 'wt') as f:
f.write(
"""
class A
{
public:
A();
void a();
private:
void b();
};
""")

test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write(
"""
#include "test.h"

A::A() { }
void A::b() { }
""")

args = [
'-q',
'--template=simple',
test_file
]

ret, stdout, stderr = cppcheck(args)
assert stdout == ''
assert stderr.splitlines() == []
assert ret == 0, stdout
2 changes: 1 addition & 1 deletion test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class TestPreprocessor : public TestFixture {
cfgs = preprocessor.getConfigs();
for (const std::string & config : cfgs) {
try {
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
const bool writeLocations = (strstr(code, "#include") != nullptr);
cfgcode[config] = preprocessor.getcode(config, files, writeLocations);
} catch (const simplecpp::Output &) {
cfgcode[config] = "";
Expand Down
19 changes: 0 additions & 19 deletions test/testunusedprivfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class TestUnusedPrivateFunction : public TestFixture {

TEST_CASE(classInClass);
TEST_CASE(sameFunctionNames);
TEST_CASE(incompleteImplementation);

TEST_CASE(derivedClass); // skip warning for derived classes. It might be a virtual function.

Expand Down Expand Up @@ -482,24 +481,6 @@ class TestUnusedPrivateFunction : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void incompleteImplementation() {
// The implementation for "A::a" is missing - so don't check if
// "A::b" is used or not
check("#file \"test.h\"\n"
"class A\n"
"{\n"
"public:\n"
" A();\n"
" void a();\n"
"private:\n"
" void b();\n"
"};\n"
"#endfile\n"
"A::A() { }\n"
"void A::b() { }");
ASSERT_EQUALS("", errout_str());
}

void derivedClass() {
// skip warning in derived classes in case the base class is invisible
check("class derived : public base\n"
Expand Down