From 33d7631ee3c420afcb14e50e3f694a79e0c9da6a Mon Sep 17 00:00:00 2001 From: amai2012 Date: Tue, 16 Jun 2015 23:11:34 +0200 Subject: [PATCH] Fix another Borlad-specific test by setting Windows platform type Refactoring: make CheckIO::ArgumentInfo aware of language (C vs. C++) to perform some optimizations --- lib/checkio.cpp | 15 +++++++++------ lib/checkio.h | 3 ++- test/testunusedprivfunc.cpp | 7 ++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 8eb306bcd..bda08435c 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -685,7 +685,7 @@ void CheckIO::checkWrongPrintfScanfArguments() } // Perform type checks - ArgumentInfo argInfo(argListTok, _settings); + ArgumentInfo argInfo(argListTok, _settings, _tokenizer->isCPP()); if (argInfo.typeToken && !argInfo.isLibraryType(_settings)) { if (scan) { @@ -1375,7 +1375,7 @@ void CheckIO::checkWrongPrintfScanfArguments() // We currently only support string literals, variables, and functions. /// @todo add non-string literals, and generic expressions -CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings) +CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings, bool isCPP) : variableInfo(0) , typeToken(0) , functionInfo(0) @@ -1383,6 +1383,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings) , _template(false) , address(false) , tempToken(0) + , isCPP(isCPP) { if (tok) { if (tok->type() == Token::eString) { @@ -1443,8 +1444,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings) tok1 = tok1->link(); // check for some common well known functions - else if ((Token::Match(tok1->previous(), "%var% . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous())) || - (Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous()->link()->previous()))) { + else if (isCPP && ((Token::Match(tok1->previous(), "%var% . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous())) || + (Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous()->link()->previous())))) { tempToken = new Token(0); tempToken->fileIndex(tok1->fileIndex()); tempToken->linenr(tok1->linenr()); @@ -1529,7 +1530,8 @@ namespace { bool CheckIO::ArgumentInfo::isStdVectorOrString() { - + if (!isCPP) + return false; if (variableInfo->isStlType(stl_vector)) { typeToken = variableInfo->typeStartToken()->tokAt(4); _template = true; @@ -1593,7 +1595,8 @@ namespace { bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok) { - + if (!isCPP) + return false; if (tok && tok->variable()) { const Variable* variable = tok->variable(); if (variable->isStlType(stl_container)) { diff --git a/lib/checkio.h b/lib/checkio.h index b62e13678..70af2d25e 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -70,7 +70,7 @@ public: private: class ArgumentInfo { public: - ArgumentInfo(const Token *arg, const Settings *settings); + ArgumentInfo(const Token *arg, const Settings *settings, bool isCPP); ~ArgumentInfo(); bool isArrayOrPointer() const; @@ -86,6 +86,7 @@ private: bool element; bool _template; bool address; + bool isCPP; Token *tempToken; private: diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index d31cc22ef..91dc9991c 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -75,12 +75,13 @@ private: } - void check(const char code[]) { + void check(const char code[], Settings::PlatformType platform = Settings::Unspecified) { // Clear the error buffer.. errout.str(""); Settings settings; settings.addEnabled("style"); + settings.platform(platform); // Tokenize.. Tokenizer tokenizer(&settings, this); @@ -517,7 +518,7 @@ private: "public:\n" " Foo() { }\n" " __property int x = {read=getx}\n" - "};"); + "};", Settings::Win32A); ASSERT_EQUALS("", errout.str()); } @@ -530,7 +531,7 @@ private: " }\n" "public:\n" " Foo() { }\n" - "};"); + "};", Settings::Win32A); ASSERT_EQUALS("", errout.str()); }