parent
6e1cc11eff
commit
c76b05ad75
|
@ -2281,7 +2281,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::set<std::string> CheckClass::stl_containers_not_const = { "map", "unordered_map" };
|
const std::set<std::string> CheckClass::stl_containers_not_const = { "map", "unordered_map", "std :: map|unordered_map <" }; // start pattern
|
||||||
|
|
||||||
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& memberAccessed) const
|
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& memberAccessed) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -1526,10 +1526,9 @@ void CheckOther::checkConstVariable()
|
||||||
callNonConstMethod = true;
|
callNonConstMethod = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (var->isStlType() && Token::Match(tok, "%var% [")) { // containers whose operator[] is non-const
|
if (var->valueType() && var->valueType()->container && Token::Match(tok, "%var% [")) { // containers whose operator[] is non-const
|
||||||
const Token* typeTok = var->typeStartToken() ? var->typeStartToken()->tokAt(2) : nullptr;
|
|
||||||
const auto& notConst = CheckClass::stl_containers_not_const;
|
const auto& notConst = CheckClass::stl_containers_not_const;
|
||||||
if (typeTok && notConst.find(typeTok->str()) != notConst.end()) {
|
if (notConst.find(var->valueType()->container->startPattern) != notConst.end()) {
|
||||||
callNonConstMethod = true;
|
callNonConstMethod = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3023,6 +3023,12 @@ private:
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(std::vector<std::map<int, int>>& v) {\n" // #11607
|
||||||
|
" for (auto& m : v)\n"
|
||||||
|
" std::cout << m[0];\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct S { int i; };\n" // #11473
|
check("struct S { int i; };\n" // #11473
|
||||||
"void f(std::vector<std::vector<S>>&m, int*& p) {\n"
|
"void f(std::vector<std::vector<S>>&m, int*& p) {\n"
|
||||||
" auto& a = m[0];\n"
|
" auto& a = m[0];\n"
|
||||||
|
|
Loading…
Reference in New Issue