diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 31797d738..8b0424f4a 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1549,6 +1549,20 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString() return true; } } + } else if (variableInfo->type()) { + const Scope * classScope = variableInfo->type()->classScope; + if (classScope) { + std::list::const_iterator functions; + for (functions = classScope->functionList.begin(); + functions != classScope->functionList.end(); ++functions) { + if (functions->name() == "operator[]") { + if (Token::Match(functions->retDef, "%type% &")) { + typeToken = functions->retDef; + return true; + } + } + } + } } return false; diff --git a/test/testio.cpp b/test/testio.cpp index 0c87ab4e9..1b2b767bb 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -3100,6 +3100,19 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n" "[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'int'.\n", errout.str()); + check("template \n" + "struct Array {\n" + " T data[S];\n" + " T & operator [] (size_t i) { return data[i]; }\n" + "};\n" + "void foo() {\n" + " Array array1;\n" + " Array array2;\n" + " printf(\"%u %u\", array1[0], array2[0]);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'.\n" + "[test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'.\n", errout.str()); + } void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings