Skip to content

Commit 9a10270

Browse files
committed
Refactoring: Disable debug warnings when file extension is neither .c nor .cpp. To somewhat prevent that people fix java/c# specific debug warnings.
1 parent 05f16a2 commit 9a10270

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/cppcheck.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,26 @@ bool CppCheck::findError(std::string code, const char FileName[])
138138
return true;
139139
}
140140

141+
// Disable debug warnings?
142+
static bool no_debug_warnings(const std::string &filename) {
143+
const std::string::size_type pos = filename.rfind(".");
144+
if (pos == std::string::npos)
145+
return false;
146+
const std::string ext = filename.substr(pos);
147+
148+
// Only allow debug warnings if file extension is c or cpp so people
149+
// won't be tempted to fix java / c# problems spotted this way.
150+
return bool(ext != ".c" && ext != ".cpp");
151+
}
152+
141153
unsigned int CppCheck::processFile()
142154
{
143155
exitcode = 0;
144156

157+
// disable debug warnings?
158+
if (no_debug_warnings(_filename))
159+
_settings.debugwarnings = false;
160+
145161
// TODO: Should this be moved out to its own function so all the files can be
146162
// analysed before any files are checked?
147163
if (_settings.test_2_pass && _settings._jobs == 1) {

0 commit comments

Comments
 (0)