Skip to content

Commit 3f46678

Browse files
committed
removed support for #file/#endfile [skip ci]
1 parent 2c5b872 commit 3f46678

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

lib/cppcheck.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,15 +1134,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
11341134
codeWithoutCfg = preprocessor.getcode(currentConfig, files, true);
11351135
});
11361136

1137-
if (startsWith(codeWithoutCfg,"#file"))
1138-
codeWithoutCfg.insert(0U, "//");
11391137
std::string::size_type pos = 0;
1140-
while ((pos = codeWithoutCfg.find("\n#file",pos)) != std::string::npos)
1141-
codeWithoutCfg.insert(pos+1U, "//");
1142-
pos = 0;
1143-
while ((pos = codeWithoutCfg.find("\n#endfile",pos)) != std::string::npos)
1144-
codeWithoutCfg.insert(pos+1U, "//");
1145-
pos = 0;
11461138
while ((pos = codeWithoutCfg.find(Preprocessor::macroChar,pos)) != std::string::npos)
11471139
codeWithoutCfg[pos] = ' ';
11481140
mErrorLogger.reportOut(codeWithoutCfg, Color::Reset);

test/cli/other_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,3 +3853,41 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
38533853
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
38543854
]
38553855
assert ret == 0, stdout
3856+
3857+
3858+
# The implementation for "A::a" is missing - so don't check if "A::b" is used or not
3859+
def test_unused_private_function_incomplete_impl(tmpdir):
3860+
test_inc = os.path.join(tmpdir, 'test.h')
3861+
with open(test_inc, 'wt') as f:
3862+
f.write(
3863+
"""
3864+
class A
3865+
{
3866+
public:
3867+
A();
3868+
void a();
3869+
private:
3870+
void b();
3871+
};
3872+
""")
3873+
3874+
test_file = os.path.join(tmpdir, 'test.cpp')
3875+
with open(test_file, 'wt') as f:
3876+
f.write(
3877+
"""
3878+
#include "test.h"
3879+
3880+
A::A() { }
3881+
void A::b() { }
3882+
""")
3883+
3884+
args = [
3885+
'-q',
3886+
'--template=simple',
3887+
test_file
3888+
]
3889+
3890+
ret, stdout, stderr = cppcheck(args)
3891+
assert stdout == ''
3892+
assert stderr.splitlines() == []
3893+
assert ret == 0, stdout

test/testpreprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class TestPreprocessor : public TestFixture {
144144
cfgs = preprocessor.getConfigs();
145145
for (const std::string & config : cfgs) {
146146
try {
147-
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
147+
const bool writeLocations = (strstr(code, "#include") != nullptr);
148148
cfgcode[config] = preprocessor.getcode(config, files, writeLocations);
149149
} catch (const simplecpp::Output &) {
150150
cfgcode[config] = "";

test/testunusedprivfunc.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class TestUnusedPrivateFunction : public TestFixture {
5858

5959
TEST_CASE(classInClass);
6060
TEST_CASE(sameFunctionNames);
61-
TEST_CASE(incompleteImplementation);
6261

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

@@ -482,24 +481,6 @@ class TestUnusedPrivateFunction : public TestFixture {
482481
ASSERT_EQUALS("", errout_str());
483482
}
484483

485-
void incompleteImplementation() {
486-
// The implementation for "A::a" is missing - so don't check if
487-
// "A::b" is used or not
488-
check("#file \"test.h\"\n"
489-
"class A\n"
490-
"{\n"
491-
"public:\n"
492-
" A();\n"
493-
" void a();\n"
494-
"private:\n"
495-
" void b();\n"
496-
"};\n"
497-
"#endfile\n"
498-
"A::A() { }\n"
499-
"void A::b() { }");
500-
ASSERT_EQUALS("", errout_str());
501-
}
502-
503484
void derivedClass() {
504485
// skip warning in derived classes in case the base class is invisible
505486
check("class derived : public base\n"

0 commit comments

Comments
 (0)