8000 added CLI option to disable "ifdef" bailout · firewave/cppcheck@61a1f0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 61a1f0c

Browse files
committed
added CLI option to disable "ifdef" bailout
1 parent 6a71e3b commit 61a1f0c

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

cli/cmdlineparser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
10311031
mSettings.cppHeaderProbe = false;
10321032
}
10331033

1034+
else if (std::strcmp(argv[i], "--no-ifdef-bailout") == 0) {
1035+
mSettings.ifdefBailout = false;
1036+
}
1037+
10341038
// Write results in file
10351039
else if (std::strncmp(argv[i], "--output-file=", 14) == 0)
10361040
mSettings.outputFile = Path::simplifyPath(argv[i] + 14);

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,7 @@ const std::set<std::string> CheckClass::stl_containers_not_const = { "map", "uno
23712371
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, MemberAccess& memberAccessed) const
23722372
{
23732373
if (mTokenizer->hasIfdef(func->functionScope->bodyStart, func->functionScope->bodyEnd))
2374-
return false;
2374+
return false; // TODO: log bailout?
23752375

23762376
auto getFuncTok = [](const Token* tok) -> const Token* {
23772377
if (Token::simpleMatch(tok, "this"))

lib/checkcondition.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ void CheckCondition::checkBadBitmaskCheck()
331331
// If there are #ifdef in the expression don't warn about redundant | to avoid FP
332332
const auto& startStop = tok->findExpressionStartEndTokens();
333333
if (mTokenizer->hasIfdef(startStop.first, startStop.second))
334-
continue;
334+
continue; // TODO: log bailout?
335335

336336
const bool isZero1 = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->getKnownIntValue() == 0);
337337
const bool isZero2 = (tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->getKnownIntValue() == 0);
@@ -765,6 +765,7 @@ void CheckCondition::multiCondition2()
765765
identicalConditionAfterEarlyExitError(cond1, secondCondition, errorPath);
766766
return ChildrenToVisit::done;
767767
}
768+
// TODO: log bailout?
768769
}
769770
return ChildrenToVisit::none;
770771
});

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ void CheckOther::checkVariableScope()
11001100
continue;
11011101

11021102
if (mTokenizer->hasIfdef(var->nameToken(), var->scope()->bodyEnd))
1103-
continue;
1103+
continue; // TODO: log bailout?
11041104

11051105
// reference of range for loop variable..
11061106
if (Token::Match(var->nameToken()->previous(), "& %var% = %var% .")) {

lib/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
259259
/** @brief Force checking the files with "too many" configurations (--force). */
260260
bool force{};
261261

262+
/** @brief Perform bailouts when #if blocks are encountered in checks. */
263+
bool ifdefBailout{true};
264+
262265
/** @brief List of include paths, e.g. "my/includes/" which should be used
263266
for finding include files inside source files. (-I) */
264267
std::list<std::string> includePaths;

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10948,6 +10948,9 @@ void Tokenizer::setDirectives(std::list<Directive> directives)
1094810948

1094910949
bool Tokenizer::hasIfdef(const Token *start, const Token *end) const
1095010950
{
10951+
if (!mSettings.ifdefBailout)
10952+
return false;
10953+
1095110954
const auto& directives = mDirectives;
1095210955
return std::any_of(directives.cbegin(), directives.cend(), [&](const Directive& d) {
1095310956
return startsWith(d.str, "#if") &&

0 commit comments

Comments
 (0)
0