Support strings in CheckStl::mismatchingContainers() (#6839)
This commit is contained in:
parent
a3eb725c3f
commit
7f6b6e43b1
|
@ -235,7 +235,7 @@ namespace {
|
|||
<< "partition_point" << "pop_heap" << "prev_permutation" << "push_heap" << "random_shuffle" << "remove" << "remove_copy"
|
||||
<< "remove_copy_if" << "remove_if" << "replace" << "replace_copy" << "replace_copy_if" << "replace_if" << "reverse" << "reverse_copy"
|
||||
<< "search_n" << "shuffle" << "sort" << "sort_heap" << "stable_partition" << "stable_sort" << "swap_ranges" << "transform" << "unique"
|
||||
<< "unique_copy" << "upper_bound";
|
||||
<< "unique_copy" << "upper_bound" << "string" << "wstring" << "u16string" << "u32string";
|
||||
const std::set<std::string> algorithm22 = make_container< std::set<std::string> >() // func(begin1 << end1 << begin2 << end2
|
||||
<< "find_end" << "find_first_of" << "includes" << "lexicographical_compare" << "merge" << "partial_sort_copy"
|
||||
<< "search" << "set_difference" << "set_intersection" << "set_symmetric_difference" << "set_union";
|
||||
|
@ -289,6 +289,14 @@ void CheckStl::mismatchingContainers()
|
|||
tok = arg1->linkAt(-1);
|
||||
}
|
||||
}
|
||||
for (unsigned int varid = 0; varid < symbolDatabase->getVariableListSize(); varid++) {
|
||||
const Variable* var = symbolDatabase->getVariableFromVarId(varid);
|
||||
if (var && var->isStlStringType() && Token::Match(var->nameToken(), "%var% (") && Token::Match(var->nameToken()->tokAt(2), pattern2.c_str())) {
|
||||
if (var->nameToken()->strAt(2) != var->nameToken()->strAt(8)) {
|
||||
mismatchingContainersError(var->nameToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -296,6 +296,20 @@ private:
|
|||
" std::vector<int>::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #6839
|
||||
check("void f(const std::wstring& a, const std::wstring& b) {\n"
|
||||
" const std::string tp1 = std::string(a.begin(), b.end());\n"
|
||||
" const std::wstring tp2 = std::string(b.begin(), a.end());\n"
|
||||
" const std::u16string tp3(a.begin(), b.end());\n"
|
||||
" const std::u32string tp4(b.begin(), a.end());\n"
|
||||
" const std::string fp1 = std::string(a.begin(), a.end());\n"
|
||||
" const std::string tp2(a.begin(), a.end());\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers are used together.\n"
|
||||
"[test.cpp:3]: (error) Iterators of different containers are used together.\n"
|
||||
"[test.cpp:4]: (error) Iterators of different containers are used together.\n"
|
||||
"[test.cpp:5]: (error) Iterators of different containers are used together.\n", errout.str());
|
||||
}
|
||||
|
||||
void iterator9() {
|
||||
|
|
Loading…
Reference in New Issue