Skip to content

Commit b53a2ff

Browse files
committed
Command line: Added --template=clang formatting
1 parent f92b167 commit b53a2ff

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ void CmdLineParser::PrintHelp()
992992
" '{file}:{line},{severity},{id},{message}' or\n"
993993
" '{file}({line}):({severity}) {message}' or\n"
994994
" '{callstack} {message}'\n"
995-
" Pre-defined templates: gcc, vs, edit.\n"
995+
" Pre-defined templates: clang, gcc, vs, edit.\n"
996996
" -v, --verbose Output more detailed error information.\n"
997997
" --version Print out version number.\n"
998998
" --xml Write results in xml format to error stream (stderr).\n"

lib/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class CPPCHECKLIB Check {
169169
ErrorPath errorPath;
170170
if (!value) {
171171
errorPath.push_back(ErrorPathItem(errtok,""));
172-
} else if (_settings->verbose) {
172+
} else if (_settings->verbose || _settings->outputFormat == "clang") {
173173
errorPath = value->errorPath;
174174
errorPath.push_back(ErrorPathItem(errtok,""));
175175
} else {

lib/errorlogger.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
399399
// Save this ErrorMessage in plain text.
400400

401401
// No template is given
402-
if (outputFormat.length() == 0) {
402+
if (outputFormat.empty()) {
403403
std::ostringstream text;
404404
if (!_callStack.empty())
405405
text << callStackToString(_callStack) << ": ";
@@ -413,6 +413,30 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
413413
return text.str();
414414
}
415415

416+
else if (outputFormat == "clang") {
417+
std::ostringstream text;
418+
text << _callStack.back().getfile()
419+
<< ':'
420+
<< _callStack.back().line
421+
<< ':'
422+
<< _callStack.back().col
423+
<< ": "
424+
<< Severity::toString(_severity)
425+
<< ": "
426+
<< (verbose ? _verboseMessage : _shortMessage)
427+
<< " [" << _id << ']';
428+
for (std::list<FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc)
429+
text << std::endl
430+
<< loc->getfile()
431+
<< ':'
432+
<< loc->line
433+
<< ':'
434+
<< loc->col
435+
<< ": note: "
436+
<< (loc->getinfo().empty() ? _shortMessage : loc->getinfo());
437+
return text.str();
438+
}
439+
416440
// template is given. Reformat the output according to it
417441
else {
418442
std::string result = outputFormat;

0 commit comments

Comments
 (0)