diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 12d99258f..d3243e3e2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -820,7 +820,7 @@ void CheckOther::strPlusChar() for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { // Declaring char variable.. - if (Token::Match(tok, "char %var% [;=]")) + if (Token::Match(tok, "char|int|short %var% [;=]")) { unsigned int varid = tok->next()->varId(); if (varid > 0 && varid < 10000) diff --git a/test/testother.cpp b/test/testother.cpp index 7a203900a..f946d091b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -431,11 +431,20 @@ private: // Strange looking pointer arithmetic.. strPlusChar("void foo()\n" "{\n" - " char ch = '/';\n" - " const char *p = \"/usr\" + ch;\n" + " char ch = 1;\n" + " const char *p = ch + \"/usr\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Unusual pointer arithmetic\n", errout.str()); - } + ASSERT_EQUALS("", errout.str()); + + // Strange looking pointer arithmetic.. + strPlusChar("void foo()\n" + "{\n" + " int i = 1;\n" + " const char* psz = \"Bla\";\n" + " const std::string str = i + psz;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void strPlusChar3() {