Skip to content

Commit bbd6576

Browse files
committed
got rid of some redundant error reporting code in CppCheck::checkInternal() [skip ci]
1 parent 1bf054e commit bbd6576

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

lib/cppcheck.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,19 +1213,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
12131213

12141214
if (!hasValidConfig && currCfg == *configurations.rbegin()) {
12151215
// If there is no valid configuration then report error..
1216-
std::string locfile = Path::fromNativeSeparators(o.location.file());
1217-
if (mSettings.relativePaths)
1218-
locfile = Path::getRelativePath(locfile, mSettings.basePaths);
1219-
1220-
ErrorMessage::FileLocation loc1(locfile, o.location.line, o.location.col);
1221-
1222-
ErrorMessage errmsg({std::move(loc1)},
1223-
file.spath(),
1224-
Severity::error,
1225-
o.msg,
1226-
"preprocessorErrorDirective",
1227-
Certainty::normal);
1228-
mErrorLogger.reportErr(errmsg);
1216+
preprocessor.error(o.location.file(), o.location.line, o.msg);
12291217
}
12301218
continue;
12311219

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
899899
if (mSettings.relativePaths)
900900
file = Path::getRelativePath(file, mSettings.basePaths);
901901

902-
locationList.emplace_back(file, linenr, 0);
902+
locationList.emplace_back(file, linenr, 0); // TODO: set column
903903
}
904904
mErrorLogger.reportErr(ErrorMessage(std::move(locationList),
905905
mFile0,

lib/preprocessor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
142142

143143
bool reportOutput(const simplecpp::OutputList &outputList, bool showerror);
144144

145+
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
146+
145147
private:
146148
static bool hasErrors(const simplecpp::Output &output);
147149

@@ -158,7 +160,6 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
158160
};
159161

160162
void missingInclude(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &header, HeaderTypes headerType);
161-
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
162163

163164
void addRemarkComments(const simplecpp::TokenList &tokens, std::vector<RemarkComment> &remarkComments) const;
164165

@@ -172,7 +173,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
172173
simplecpp::FileDataCache mFileCache;
173174

174175
/** filename for cpp/c file - useful when reporting errors */
175-
std::string mFile0;
176+
std::string mFile0; // TODO: this is never set
176177
Standards::Language mLang{Standards::Language::None};
177178

178179
/** simplecpp tracking info */

test/cli/other_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,7 +3429,8 @@ def test_preprocess_enforced_cpp(tmp_path): # #10989
34293429
assert exitcode == 0, stdout if stdout else stderr
34303430
assert stdout.splitlines() == []
34313431
assert stderr.splitlines() == [
3432-
'{}:2:2: error: #error "err" [preprocessorErrorDirective]'.format(test_file)
3432+
# TODO: lacks column information
3433+
'{}:2:0: error: #error "err" [preprocessorErrorDirective]'.format(test_file)
34333434
]
34343435

34353436

@@ -3924,7 +3925,7 @@ def test_simplecpp_include_nested_too_deeply(tmp_path):
39243925
# TODO: should report another ID
39253926
# TODO: lacks column information
39263927
'{}:1:0: error: #include nested too deeply [preprocessorErrorDirective]'.format(test_h),
3927-
'{}:1:2: error: #include nested too deeply [preprocessorErrorDirective]'.format(test_h)
3928+
'{}:1:0: error: #include nested too deeply [preprocessorErrorDirective]'.format(test_h)
39283929
]
39293930

39303931

@@ -3948,5 +3949,5 @@ def test_simplecpp_syntax_error(tmp_path):
39483949
# TODO: should report another ID
39493950
# TODO: lacks column information
39503951
'{}:1:0: error: No header in #include [preprocessorErrorDirective]'.format(test_file),
3951-
'{}:1:2: error: No header in #include [preprocessorErrorDirective]'.format(test_file)
3952+
'{}:1:0: error: No header in #include [preprocessorErrorDirective]'.format(test_file)
39523953
]

0 commit comments

Comments
 (0)