diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 59e1800f1..07c914791 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -940,6 +940,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() for (Variables::VariableMap::const_iterator it = variables.varUsage().begin(); it != variables.varUsage().end(); ++it) { const Variables::VariableUsage &usage = it->second; const std::string &varname = usage._name->str(); + const Variable* var = symbolDatabase->getVariableFromVarId(it->first); // variable has been marked as unused so ignore it if (usage._name->isUnused()) @@ -961,7 +962,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() unusedVariableError(usage._name, varname); // variable has not been written but has been modified - else if (usage._modified && !usage._write && !usage._allocateMemory) + else if (usage._modified && !usage._write && !usage._allocateMemory && !Token::simpleMatch(var->typeStartToken(), "std ::")) unassignedVariableError(usage._name, varname); // variable has been written but not read @@ -969,7 +970,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() unreadVariableError(usage._name, varname); // variable has been read but not written - else if (!usage._write && !usage._allocateMemory) + else if (!usage._write && !usage._allocateMemory && !Token::simpleMatch(var->typeStartToken(), "std ::")) unassignedVariableError(usage._name, varname); } } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 174f383bf..7b449e4ea 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3087,10 +3087,10 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) Variable 's' is assigned a value that is never used\n", errout.str()); functionVariableUsage("std::string foo() {\n" - " std::string s;\n" + " std::string s;\n" // Class instances are initialized. Assignement is not necessary " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 's' is not assigned a value\n", errout.str()); + ASSERT_EQUALS("", errout.str()); functionVariableUsage("std::string foo() {\n" " std::string s = \"foo\";\n"