File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1549,6 +1549,20 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
15491549 return true ;
15501550 }
15511551 }
1552+ } else if (variableInfo->type ()) {
1553+ const Scope * classScope = variableInfo->type ()->classScope ;
1554+ if (classScope) {
1555+ std::list<Function>::const_iterator functions;
1556+ for (functions = classScope->functionList .begin ();
1557+ functions != classScope->functionList .end (); ++functions) {
1558+ if (functions->name () == " operator[]" ) {
1559+ if (Token::Match (functions->retDef , " %type% &" )) {
1560+ typeToken = functions->retDef ;
1561+ return true ;
1562+ }
1563+ }
1564+ }
1565+ }
15521566 }
15531567
15541568 return false ;
Original file line number Diff line number Diff line change @@ -3100,6 +3100,19 @@ class TestIO : public TestFixture {
31003100 ASSERT_EQUALS (" [test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n "
31013101 " [test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'int'.\n " , errout.str ());
31023102
3103+ check (" template <class T, size_t S>\n "
3104+ " struct Array {\n "
3105+ " T data[S];\n "
3106+ " T & operator [] (size_t i) { return data[i]; }\n "
3107+ " };\n "
3108+ " void foo() {\n "
3109+ " Array<int, 10> array1;\n "
3110+ " Array<float, 10> array2;\n "
3111+ " printf(\" %u %u\" , array1[0], array2[0]);\n "
3112+ " }\n " );
3113+ ASSERT_EQUALS (" [test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'.\n "
3114+ " [test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'.\n " , errout.str ());
3115+
31033116 }
31043117
31053118 void testPosixPrintfScanfParameterPosition () { // #4900 - No support for parameters in format strings
You can’t perform that action at this time.
0 commit comments