Skip to content

Commit d23c58d

Browse files
author
Daniel Marjamäki
committed
enable: break out 'performance' and 'portability' from the 'style' id. Ticket: danmar#3074
1 parent 92c2df0 commit d23c58d

16 files changed

+27
-16
lines changed

cli/cmdlineparser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@ void CmdLineParser::PrintHelp()
664664
" Enable all checks\n"
665665
" * style\n"
666666
" Check coding style\n"
667+
" * performance\n"
668+
" Check for performance problems\n"
669+
" * portability\n"
670+
" Check for portability problems\n"
667671
" * information\n"
668672
" Enable information messages\n"
669673
" * unusedFunction\n"

lib/check64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static bool isint(const Variable *var)
4646

4747
void Check64BitPortability::pointerassignment()
4848
{
49-
if (!_settings->isEnabled("style"))
49+
if (!_settings->isEnabled("portability"))
5050
return;
5151

5252
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

lib/checkbufferoverrun.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
10571057
if (varid && Token::Match(tok, "= %varid% + %num% ;", varid))
10581058
{
10591059
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
1060-
if (index > size && _settings->isEnabled("style"))
1060+
if (index > size && _settings->isEnabled("portability"))
10611061
pointerOutOfBoundsError(tok->next(), "buffer");
10621062
if (index >= size && Token::Match(tok->tokAt(-2), "[;{}] %varid% =", varid))
10631063
pointerIsOutOfBounds = true;
@@ -1276,7 +1276,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
12761276
}
12771277

12781278
// undefined behaviour: result of pointer arithmetic is out of bounds
1279-
if (_settings->isEnabled("style") && Token::Match(tok, "= %varid% + %num% ;", arrayInfo.varid()))
1279+
if (_settings->isEnabled("portability") && Token::Match(tok, "= %varid% + %num% ;", arrayInfo.varid()))
12801280
{
12811281
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
12821282
if (index < 0 || index > arrayInfo.num(0))

lib/checknonreentrantfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CheckNonReentrantFunctions instance;
3333

3434
void CheckNonReentrantFunctions::nonReentrantFunctions()
3535
{
36-
if (!_settings->posix || !_settings->isEnabled("style"))
36+
if (!_settings->posix || !_settings->isEnabled("portability"))
3737
return;
3838

3939
// Don't check C# and Java code

lib/checkother.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname
15761576
//---------------------------------------------------------------------------
15771577
void CheckOther::checkConstantFunctionParameter()
15781578
{
1579-
if (!_settings->isEnabled("style"))
1579+
if (!_settings->isEnabled("performance"))
15801580
return;
15811581

15821582
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
@@ -2368,7 +2368,7 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2,
23682368
//---------------------------------------------------------------------------
23692369
void CheckOther::checkAlwaysTrueOrFalseStringCompare()
23702370
{
2371-
if (!_settings->isEnabled("style"))
2371+
if (!_settings->isEnabled("style") && !_settings->isEnabled("performance"))
23722372
return;
23732373

23742374
const char pattern1[] = "strcmp|stricmp|strcmpi|strcasecmp|wcscmp ( %str% , %str% )";
@@ -2403,7 +2403,7 @@ void CheckOther::alwaysTrueFalseStringCompareError(const Token *tok, const std::
24032403
"If the purpose is to compare these two strings, the comparison is unnecessary. "
24042404
"If the strings are supposed to be different, then there is a bug somewhere.");
24052405
}
2406-
else
2406+
else if (_settings->isEnabled("performance"))
24072407
{
24082408
reportError(tok, Severity::performance, "staticStringCompare",
24092409
"Unnecessary comparison of static strings.\n"

lib/checkpostfixoperator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CheckPostfixOperator instance;
3535

3636
void CheckPostfixOperator::postfixOperator()
3737
{
38-
if (!_settings->isEnabled("style"))
38+
if (!_settings->isEnabled("performance"))
3939
return;
4040

4141
const Token *tok = _tokenizer->tokens();

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ bool CheckStl::isStlContainer(unsigned int varid)
848848

849849
void CheckStl::size()
850850
{
851-
if (!_settings->isEnabled("style"))
851+
if (!_settings->isEnabled("performance"))
852852
return;
853853

854854
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

lib/settings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ std::string Settings::addEnabled(const std::string &str)
7878

7979
std::set<std::string> id;
8080
id.insert("style");
81+
id.insert("performance");
82+
id.insert("portability");
83+
id.insert("information");
8184
id.insert("missingInclude");
8285
id.insert("unusedFunction");
83-
id.insert("information");
8486

8587
if (str == "all")
8688
{

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10179,7 +10179,8 @@ void Tokenizer::removeUnnecessaryQualification()
1017910179
continue;
1018010180
}
1018110181

10182-
unnecessaryQualificationError(tok, qualification);
10182+
if (_settings && _settings->isEnabled("portability"))
10183+
unnecessaryQualificationError(tok, qualification);
1018310184

1018410185
tok->deleteThis();
1018510186
tok->deleteThis();

test/test64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Test64BitPortability : public TestFixture
4747
errout.str("");
4848

4949
Settings settings;
50-
settings.addEnabled("style");
50+
settings.addEnabled("portability");
5151

5252
// Tokenize..
5353
Tokenizer tokenizer(&settings, this);

0 commit comments

Comments
 (0)