diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 64158c400..7eab3f38f 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -371,6 +371,9 @@ static bool astHasAutoResult(const Token *tok) void CheckAutoVariables::returnReference() { + if (_tokenizer->isC()) + return; + const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const std::size_t functions = symbolDatabase->functionScopes.size(); diff --git a/lib/checkio.cpp b/lib/checkio.cpp index cec3053b9..91a33e783 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -38,6 +38,9 @@ namespace { //--------------------------------------------------------------------------- void CheckIO::checkCoutCerrMisusage() { + if (_tokenizer->isC()) + return; + const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 945d7fa01..749501c40 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -777,31 +777,33 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } - // fill in base class info - for (std::list::iterator it = typeList.begin(); it != typeList.end(); ++it) { - // finish filling in base class info - for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) - it->derivedFrom[i].type = findType(it->derivedFrom[i].nameTok, it->enclosingScope); - } - - // fill in friend info - for (std::list::iterator it = typeList.begin(); it != typeList.end(); ++it) { - for (std::list::iterator i = it->friendList.begin(); i != it->friendList.end(); ++i) { - i->type = findType(i->nameStart, it->enclosingScope); + if (!_tokenizer->isC()) { + // fill in base class info + for (std::list::iterator it = typeList.begin(); it != typeList.end(); ++it) { + // finish filling in base class info + for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) + it->derivedFrom[i].type = findType(it->derivedFrom[i].nameTok, it->enclosingScope); } - } - // fill in using info - for (std::list::iterator it = scopeList.begin(); it != scopeList.end(); ++it) { - for (std::list::iterator i = it->usingList.begin(); i != it->usingList.end(); ++i) { - // only find if not already found - if (i->scope == nullptr) { - // check scope for match - scope = findScope(i->start->tokAt(2), &(*it)); - if (scope) { - // set found scope - i->scope = scope; - break; + // fill in friend info + for (std::list::iterator it = typeList.begin(); it != typeList.end(); ++it) { + for (std::list::iterator i = it->friendList.begin(); i != it->friendList.end(); ++i) { + i->type = findType(i->nameStart, it->enclosingScope); + } + } + + // fill in using info + for (std::list::iterator it = scopeList.begin(); it != scopeList.end(); ++it) { + for (std::list::iterator i = it->usingList.begin(); i != it->usingList.end(); ++i) { + // only find if not already found + if (i->scope == nullptr) { + // check scope for match + scope = findScope(i->start->tokAt(2), &(*it)); + if (scope) { + // set found scope + i->scope = scope; + break; + } } } } @@ -1210,14 +1212,14 @@ void Variable::evaluate() bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth) { const bool isCPP = scope->check->isCPP(); + if (!isCPP) // C does not support overloads + return true; - // skip "struct" if it is C++ - if (isCPP) { - if (first->str() == "struct") - first = first->next(); - if (second->str() == "struct") - second = second->next(); - } + // skip "struct" + if (first->str() == "struct") + first = first->next(); + if (second->str() == "struct") + second = second->next(); // skip const on type passed by value if (Token::Match(first, "const %type% %var%|,|)")) @@ -1339,13 +1341,11 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se first = first->next(); second = second->next(); - // skip "struct" if it is C++ - if (isCPP) { - if (first->str() == "struct") - first = first->next(); - if (second->str() == "struct") - second = second->next(); - } + // skip "struct" + if (first->str() == "struct") + first = first->next(); + if (second->str() == "struct") + second = second->next(); // skip const on type passed by value if (Token::Match(first, "const %type% %var%|,|)")) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a77a9b915..cd51d749c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3247,7 +3247,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // ";a+=b;" => ";a=a+b;" simplifyCompoundAssignment(); - if (!_settings->library.markupFile(FileName)) { + if (!isC() && !_settings->library.markupFile(FileName)) { findComplicatedSyntaxErrorsInTemplates(); } @@ -3461,7 +3461,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // then unsimplified function calls etc remain. These have the // "wrong" syntax. So this function will just fix so that the // syntax is corrected. - TemplateSimplifier::cleanupAfterSimplify(list.front()); + if (!isC()) + TemplateSimplifier::cleanupAfterSimplify(list.front()); // Collapse operator name tokens into single token // operator = => operator= @@ -6220,6 +6221,9 @@ bool Tokenizer::simplifyCAlternativeTokens() // int i(0), j; => int i; i = 0; int j; void Tokenizer::simplifyInitVar() { + if (isC()) + return; + for (Token *tok = list.front(); tok; tok = tok->next()) { if (!tok->isName() || (tok->previous() && !Token::Match(tok->previous(), "[;{}]"))) continue; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 2d09550b6..790ba7477 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -563,7 +563,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state) } else compileBinOp(tok, state, compileScope); } else if (tok->str() == "[") { - if (isPrefixUnary(tok, state.cpp) && tok->link()->strAt(1) == "(") { // Lambda + if (state.cpp && isPrefixUnary(tok, state.cpp) && tok->link()->strAt(1) == "(") { // Lambda // What we do here: // - Nest the round bracket under the square bracket. // - Nest what follows the lambda (if anything) with the lambda opening [