Skip to content
Merged
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
18 changes: 18 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,24 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
// #error etc during preprocessing
configurationError.push_back((mCurrentConfig.empty() ? "\'\'" : mCurrentConfig) + " : [" + o.location.file() + ':' + std::to_string(o.location.line) + "] " + o.msg);
--checkCount; // don't count invalid configurations

if (!hasValidConfig && currCfg == *configurations.rbegin()) {
// If there is no valid configuration then report error..
std::string file = Path::fromNativeSeparators(o.location.file());
if (mSettings.relativePaths)
file = Path::getRelativePath(file, mSettings.basePaths);

const ErrorMessage::FileLocation loc1(file, o.location.line, o.location.col);
std::list<ErrorMessage::FileLocation> callstack(1, loc1);

ErrorMessage errmsg(callstack,
filename,
Severity::error,
o.msg,
"preprocessorErrorDirective",
Certainty::normal);
reportErr(errmsg);
}
continue;

} catch (const TerminateException &) {
Expand Down
9 changes: 9 additions & 0 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def test_missing_include_inline_suppr(tmpdir):
assert stderr == ''


def test_preprocessor_error(tmpdir):
test_file = os.path.join(tmpdir, '10866.c')
with open(test_file, 'wt') as f:
f.write('#error test\nx=1;\n')
exitcode, _, stderr = cppcheck(['--error-exitcode=1', test_file])
assert 'preprocessorErrorDirective' in stderr
assert exitcode != 0


def test_invalid_library(tmpdir):
args = ['--library=none', '--library=posix', '--library=none2', 'file.c']

Expand Down