Fixed #9193 (functionStatic false positive (inconclusive)) (#1943)

This commit is contained in:
IOBYTE 2019-07-02 05:40:57 -04:00 committed by Daniel Marjamäki
parent cca1a6aa2e
commit 5642778206
3 changed files with 29 additions and 1 deletions

View File

@ -1094,19 +1094,21 @@ void TemplateSimplifier::useDefaultArgumentValues(TokenAndName &declaration)
continue;
if (end != instantiation.token->tokAt(2))
instantiationArgs.resize(1);
for (const Token *tok1 = instantiation.token->tokAt(2); tok1 && tok1!= end; tok1 = tok1->next()) {
for (const Token *tok1 = instantiation.token->tokAt(2); tok1 && tok1 != end; tok1 = tok1->next()) {
if (tok1->link() && Token::Match(tok1, "{|(|[")) {
const Token *endLink = tok1->link();
do {
instantiationArgs[index].push_back(tok1);
tok1 = tok1->next();
} while (tok1 && tok1 != endLink);
instantiationArgs[index].push_back(tok1);
} else if (tok1->str() == "<" && (tok1->strAt(1) == ">" || templateParameters(tok1))) {
const Token *endLink = tok1->findClosingBracket();
do {
instantiationArgs[index].push_back(tok1);
tok1 = tok1->next();
} while (tok1 && tok1 != endLink);
instantiationArgs[index].push_back(tok1);
} else if (tok1->str() == ",") {
++index;
instantiationArgs.resize(index + 1);

View File

@ -174,6 +174,7 @@ private:
TEST_CASE(const64); // ticket #6268
TEST_CASE(const65); // ticket #8693
TEST_CASE(const66); // ticket #7714
TEST_CASE(const67); // ticket #9193
TEST_CASE(const_handleDefaultParameters);
TEST_CASE(const_passThisToMemberOfOtherClass);
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
@ -5661,6 +5662,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const67() { // #9193
checkConst("template <class VALUE_T, class LIST_T = std::list<VALUE_T> >\n"
"class TestList {\n"
"public:\n"
" LIST_T m_list;\n"
"};\n"
"class Test {\n"
"public:\n"
" const std::list<std::shared_ptr<int>>& get() { return m_test.m_list; }\n"
" TestList<std::shared_ptr<int>> m_test;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Test::get' can be const.\n", errout.str());
}
void const_handleDefaultParameters() {
checkConst("struct Foo {\n"
" void foo1(int i, int j = 0) {\n"

View File

@ -158,6 +158,7 @@ private:
TEST_CASE(template118);
TEST_CASE(template119); // #9186
TEST_CASE(template120);
TEST_CASE(template121); // #9193
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@ -2849,6 +2850,16 @@ private:
ASSERT_EQUALS(exp, tok(code));
}
void template121() { // #9193
const char code[] = "template <class VALUE_T, class LIST_T = std::list<VALUE_T>>\n"
"class TestList { };\n"
"TestList<std::shared_ptr<int>> m_test;";
const char exp[] = "class TestList<std::shared_ptr<int>,std::list<std::shared_ptr<int>>> ; "
"TestList<std::shared_ptr<int>,std::list<std::shared_ptr<int>>> m_test ; "
"class TestList<std::shared_ptr<int>,std::list<std::shared_ptr<int>>> { } ;";
ASSERT_EQUALS(exp, tok(code));
}
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"