Skip to content

Commit e6807a4

Browse files
authored
fixed #14675 - provide proper error ID for simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND (#8462)
1 parent 2feda02 commit e6807a4

2 files changed

Lines changed: 133 additions & 1 deletion

File tree

lib/preprocessor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,9 @@ static std::string simplecppErrToId(simplecpp::Output::Type type)
997997
return "includeNestedTooDeeply";
998998
case simplecpp::Output::FILE_NOT_FOUND:
999999
return "missingFile";
1000-
// should never occur
10011000
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
1001+
return "missingIncludeExplicit";
1002+
// should never occur
10021003
case simplecpp::Output::DUI_ERROR:
10031004
// handled separately
10041005
case simplecpp::Output::MISSING_HEADER:
@@ -1074,6 +1075,7 @@ void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &se
10741075
preprocessor.error(loc, "message", simplecpp::Output::UNHANDLED_CHAR_ERROR);
10751076
preprocessor.error(loc, "message", simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY);
10761077
preprocessor.error(loc, "message", simplecpp::Output::FILE_NOT_FOUND);
1078+
preprocessor.error(loc, "message", simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND);
10771079
preprocessor.invalidSuppression(loc, "message");
10781080
}
10791081

test/cli/other_test.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,3 +4427,133 @@ def test_inline_block_suppr_builddir_twice(tmp_path):
44274427
assert exitcode == 0
44284428
assert stdout == ''
44294429
assert stderr == ''
4430+
4431+
4432+
def test_dui_include(tmp_path):
4433+
test_file = tmp_path / 'test.c'
4434+
with open(test_file, "w") as f:
4435+
f.write('void f() {}')
4436+
4437+
inc_file = tmp_path / 'inc.h'
4438+
with open(inc_file, "w") as f:
4439+
f.write(
4440+
"""
4441+
void f_i()
4442+
{
4443+
(void)(*((int*)0));
4444+
}
4445+
""")
4446+
4447+
args = [
4448+
'-q',
4449+
'--template=simple',
4450+
f'--include={inc_file}',
4451+
str(test_file)
4452+
]
4453+
4454+
exitcode, stdout, stderr = cppcheck(args)
4455+
assert exitcode == 0
4456+
assert stdout == ''
4457+
assert stderr.splitlines() == [
4458+
f'{inc_file}:4:14: error: Null pointer dereference: (int*)0 [nullPointer]'
4459+
]
4460+
4461+
4462+
def test_dui_include_missing(tmp_path): # #14675
4463+
test_file = tmp_path / 'test.c'
4464+
with open(test_file, "w") as f:
4465+
f.write('void f() {}')
4466+
4467+
args = [
4468+
'-q',
4469+
'--template=simple',
4470+
'--include=missing.h',
4471+
str(test_file)
4472+
]
4473+
4474+
exitcode, stdout, stderr = cppcheck(args)
4475+
assert exitcode == 0
4476+
assert stdout == ''
4477+
assert stderr.splitlines() == [
4478+
f"{test_file}:0:0: error: Can not open include file 'missing.h' that is explicitly included. [missingIncludeExplicit]"
4479+
]
4480+
4481+
4482+
def test_dui_include_relative(tmp_path):
4483+
test_file = tmp_path / 'test.c'
4484+
with open(test_file, "w") as f:
4485+
f.write('void f() {}')
4486+
4487+
inc_file = tmp_path / 'inc.h'
4488+
with open(inc_file, "w") as f:
4489+
f.write(
4490+
"""
4491+
void f_i()
4492+
{
4493+
(void)(*((int*)0));
4494+
}
4495+
""")
4496+
4497+
args = [
4498+
'-q',
4499+
'--template=simple',
4500+
'--include=inc.h',
4501+
str(test_file)
4502+
]
4503+
4504+
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
4505+
assert exitcode == 0
4506+
assert stdout == ''
4507+
assert stderr.splitlines() == [
4508+
'inc.h:4:14: error: Null pointer dereference: (int*)0 [nullPointer]'
4509+
]
4510+
4511+
4512+
def test_dui_include_relative_missing(tmp_path):
4513+
test_file = tmp_path / 'test.c'
4514+
with open(test_file, "w") as f:
4515+
f.write('void f() {}')
4516+
4517+
inc_file = tmp_path / 'inc.h'
4518+
with open(inc_file, "w") as f:
4519+
f.write(
4520+
"""
4521+
void f_i()
4522+
{
4523+
(void)(*((int*)0));
4524+
}
4525+
""")
4526+
4527+
args = [
4528+
'-q',
4529+
'--template=simple',
4530+
'--include=inc.h',
4531+
str(test_file)
4532+
]
4533+
4534+
exitcode, stdout, stderr = cppcheck(args,)
4535+
assert exitcode == 0
4536+
assert stdout == ''
4537+
assert stderr.splitlines() == [
4538+
f"{test_file}:0:0: error: Can not open include file 'inc.h' that is explicitly included. [missingIncludeExplicit]"
4539+
]
4540+
4541+
4542+
def test_dui_include_absolute_missing(tmp_path): # #14675
4543+
test_file = tmp_path / 'test.c'
4544+
with open(test_file, "w") as f:
4545+
f.write('void f() {}')
4546+
4547+
args = [
4548+
'-q',
4549+
'--template=simple',
4550+
'--include=/share/include/missing.h',
4551+
str(test_file)
4552+
]
4553+
4554+
exitcode, stdout, stderr = cppcheck(args)
4555+
assert exitcode == 0
4556+
assert stdout == ''
4557+
assert stderr.splitlines() == [
4558+
f"{test_file}:0:0: error: Can not open include file '/share/include/missing.h' that is explicitly included. [missingIncludeExplicit]"
4559+
]

0 commit comments

Comments
 (0)