Skip to content

Commit 5940d77

Browse files
committed
Disabled C++ specific checks and simplifications when checking a C or non-C++ file.
1 parent 87131f6 commit 5940d77

9 files changed

Lines changed: 42 additions & 9 deletions

‎lib/checkboost.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class CPPCHECKLIB CheckBoost : public Check {
4545

4646
/** Simplified checks. The token list is simplified. */
4747
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
48+
if (!tokenizer->isCPP())
49+
return;
50+
4851
CheckBoost checkBoost(tokenizer, settings, errorLogger);
4952

5053
checkBoost.checkBoostForeachModification();

‎lib/checkclass.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class CPPCHECKLIB CheckClass : public Check {
4444

4545
/** @brief Run checks on the normal token list */
4646
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
47+
if (tokenizer->isC())
48+
return;
49+
4750
CheckClass checkClass(tokenizer, settings, errorLogger);
4851

4952
// can't be a simplified check .. the 'sizeof' is used.
@@ -52,6 +55,9 @@ class CPPCHECKLIB CheckClass : public Check {
5255

5356
/** @brief Run checks on the simplified token list */
5457
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
58+
if (tokenizer->isC())
59+
return;
60+
5561
CheckClass checkClass(tokenizer, settings, errorLogger);
5662

5763
// Coding style checks

‎lib/checkexceptionsafety.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class CPPCHECKLIB CheckExceptionSafety : public Check {
5353

5454
/** Checks that uses the simplified token list */
5555
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
56+
if (tokenizer->isC())
57+
return;
58+
5659
CheckExceptionSafety checkExceptionSafety(tokenizer, settings, errorLogger);
5760
checkExceptionSafety.destructors();
5861
checkExceptionSafety.deallocThrow();

‎lib/checkmemoryleak.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class CPPCHECKLIB CheckMemoryLeakInClass : private Check, private CheckMemoryLea
363363

364364
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) {
365365
// Don't use these check for Java and C# programs..
366-
if (tokenizr->isJavaOrCSharp())
366+
if (!tokenizr->isCPP())
367367
return;
368368

369369
CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog);

‎lib/checkother.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname
18711871
//---------------------------------------------------------------------------
18721872
void CheckOther::checkConstantFunctionParameter()
18731873
{
1874-
if (!_settings->isEnabled("performance"))
1874+
if (!_settings->isEnabled("performance") || _tokenizer->isC())
18751875
return;
18761876

18771877
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
@@ -3276,7 +3276,7 @@ In most scenarios, "const A & a = getA()" will be more efficient.
32763276
*/
32773277
void CheckOther::checkRedundantCopy()
32783278
{
3279-
if (!_settings->isEnabled("performance"))
3279+
if (!_settings->isEnabled("performance") || _tokenizer->isC())
32803280
return;
32813281

32823282
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

‎lib/checkpostfixoperator.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class CPPCHECKLIB CheckPostfixOperator : public Check {
4444
{ }
4545

4646
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
47+
if (tokenizer->isC())
48+
return;
49+
4750
CheckPostfixOperator checkPostfixOperator(tokenizer, settings, errorLogger);
4851
checkPostfixOperator.postfixOperator();
4952
}

‎lib/checkstl.cpp‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,9 +1072,6 @@ static bool isLocal(const SymbolDatabase* symbolDatabase, unsigned int varid)
10721072

10731073
void CheckStl::string_c_str()
10741074
{
1075-
if (!_tokenizer->isCPP())
1076-
return;
1077-
10781075
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
10791076

10801077
// Find all functions that take std::string as argument
@@ -1238,9 +1235,6 @@ static bool hasArrayEndParen(const Token *tok1)
12381235
//---------------------------------------------------------------------------
12391236
void CheckStl::checkAutoPointer()
12401237
{
1241-
if (!_tokenizer->isCPP())
1242-
return;
1243-
12441238
std::set<unsigned int> autoPtrVarId;
12451239
static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
12461240

‎lib/checkstl.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class CPPCHECKLIB CheckStl : public Check {
4545

4646
/** Simplified checks. The token list is simplified. */
4747
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
48+
if (!tokenizer->isCPP())
49+
return;
50+
4851
CheckStl checkStl(tokenizer, settings, errorLogger);
4952

5053
checkStl.stlOutOfBounds();

‎lib/tokenize.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,9 @@ bool Tokenizer::hasComplicatedSyntaxErrorsInTemplates()
20752075

20762076
void Tokenizer::simplifyDefaultAndDeleteInsideClass()
20772077
{
2078+
if (isC())
2079+
return;
2080+
20782081
// Remove "= default|delete" inside class|struct definitions
20792082
// Todo: Remove it if it is used "externally" too.
20802083
for (Token *tok = list.front(); tok; tok = tok->next()) {
@@ -2487,6 +2490,9 @@ void Tokenizer::simplifyLabelsCaseDefault()
24872490

24882491
void Tokenizer::simplifyTemplates()
24892492
{
2493+
if (isC())
2494+
return;
2495+
24902496
for (Token *tok = list.front(); tok; tok = tok->next()) {
24912497
// #2648 - simple fix for sizeof used as template parameter
24922498
// TODO: this is a bit hardcoded. make a bit more generic
@@ -6640,6 +6646,9 @@ bool Tokenizer::simplifyRedundantParenthesis()
66406646

66416647
void Tokenizer::simplifyReference()
66426648
{
6649+
if (isC())
6650+
return;
6651+
66436652
for (Token *tok = list.front(); tok; tok = tok->next()) {
66446653
// starting executable scope..
66456654
if (Token::Match(tok, ") const| {")) {
@@ -7432,6 +7441,9 @@ void Tokenizer::simplifyEnum()
74327441

74337442
void Tokenizer::simplifyStd()
74347443
{
7444+
if (isC())
7445+
return;
7446+
74357447
std::set<std::string> f;
74367448
f.insert("strcat");
74377449
f.insert("strcpy");
@@ -7946,6 +7958,9 @@ void Tokenizer::simplifyComma()
79467958

79477959
void Tokenizer::removeExceptionSpecifications()
79487960
{
7961+
if (isC())
7962+
return;
7963+
79497964
for (Token* tok = list.front(); tok; tok = tok->next()) {
79507965
if (Token::Match(tok, ") const| throw (")) {
79517966
if (tok->next()->str() == "const") {
@@ -9063,6 +9078,9 @@ void Tokenizer::deleteSymbolDatabase()
90639078

90649079
void Tokenizer::simplifyOperatorName()
90659080
{
9081+
if (isC())
9082+
return;
9083+
90669084
for (Token *tok = list.front(); tok; tok = tok->next()) {
90679085
if (tok->str() == "operator") {
90689086
// operator op
@@ -9117,6 +9135,9 @@ void Tokenizer::simplifyOperatorName()
91179135
// remove unnecessary member qualification..
91189136
void Tokenizer::removeUnnecessaryQualification()
91199137
{
9138+
if (isC())
9139+
return;
9140+
91209141
std::vector<Space> classInfo;
91219142
for (Token *tok = list.front(); tok; tok = tok->next()) {
91229143
if (Token::Match(tok, "class|struct|namespace %type% :|{") &&

0 commit comments

Comments
 (0)