Skip to content

Commit 3aad50b

Browse files
committed
removed support for #file/#endfile [skip ci]
1 parent 21163e8 commit 3aad50b

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
@@ -1124,15 +1124,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
11241124
codeWithoutCfg = preprocessor.getcode(currentConfig, files, true);
11251125
});
11261126

1127-
if (startsWith(codeWithoutCfg,"#file"))
1128-
codeWithoutCfg.insert(0U, "//");
11291127
std::string::size_type pos = 0;
1130-
while ((pos = codeWithoutCfg.find("\n#file",pos)) != std::string::npos)
1131-
codeWithoutCfg.insert(pos+1U, "//");
1132-
pos = 0;
1133-
while ((pos = codeWithoutCfg.find("\n#endfile",pos)) != std::string::npos)
1134-
codeWithoutCfg.insert(pos+1U, "//");
1135-
pos = 0;
11361128
while ((pos = codeWithoutCfg.find(Preprocessor::macroChar,pos)) != std::string::npos)
11371129
codeWithoutCfg[pos] = ' ';
11381130
mErrorLogger.reportOut(codeWithoutCfg, Color::Reset);

test/cli/other_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3986,3 +3986,41 @@ def test_max_configs(tmp_path, max_configs, number_of_configs, check_config, exp
39863986
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks {} of {} configurations. Use --force to check all configurations. [toomanyconfigs]'
39873987
.format(test_file, max_configs, number_of_configs)
39883988
]
3989+
3990+
3991+
# The implementation for "A::a" is missing - so don't check if "A::b" is used or not
3992+
def test_unused_private_function_incomplete_impl(tmpdir):
3993+
test_inc = os.path.join(tmpdir, 'test.h')
3994+
with open(test_inc, 'wt') as f:
3995+
f.write(
3996+
"""
3997+
class A
3998+
{
3999+
public:
4000+
A();
4001+
void a();
4002+
private:
4003+
void b();
4004+
};
4005+
""")
4006+
4007+
test_file = os.path.join(tmpdir, 'test.cpp')
4008+
with open(test_file, 'wt') as f:
4009+
f.write(
4010+
"""
4011+
#include "test.h"
4012+
4013+
A::A() { }
4014+
void A::b() { }
4015+
""")
4016+
4017+
args = [
4018+
'-q',
4019+
'--template=simple',
4020+
test_file
4021+
]
4022+
4023+
ret, stdout, stderr = cppcheck(args)
4024+
assert stdout == ''
4025+
assert stderr.splitlines() == []
4026+
assert ret == 0, stdout

test/testpreprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TestPreprocessor : public TestFixture {
135135
cfgs = preprocessor.getConfigs();
136136
for (const std::string & config : cfgs) {
137137
try {
138-
const bool writeLocations = (strstr(code, "#file") != nullptr) || (strstr(code, "#include") != nullptr);
138+
const bool writeLocations = (strstr(code, "#include") != nullptr);
139139
cfgcode[config] = preprocessor.getcode(config, files, writeLocations);
140140
} catch (const simplecpp::Output &) {
141141
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)