From a9f29fbc096867f1a92f38bd7e7220d7a13257ce Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 1 Apr 2022 23:26:44 +0200 Subject: [PATCH] Fix #10307 FP functionStatic with class template and east-const / #10471 FP constParameter with std::array and east-const (#3963) --- lib/symboldatabase.cpp | 4 ++-- test/testclass.cpp | 10 ++++++++++ test/testother.cpp | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 57dc6d46c..b1edc11db 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4556,7 +4556,7 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok, if (!localVarTok) return false; - if (localVarTok->str() == "const") + while (Token::Match(localVarTok, "const|*|&")) localVarTok = localVarTok->next(); if (Token::Match(localVarTok, "%name% ;|=") || (localVarTok && localVarTok->varId() && localVarTok->strAt(1) == ":")) { @@ -6373,7 +6373,7 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V } else if (const Library::Container *container = settings->library.detectContainer(type)) { valuetype->type = ValueType::Type::CONTAINER; valuetype->container = container; - while (Token::Match(type, "%type%|::|<")) { + while (Token::Match(type, "%type%|::|<") && type->str() != "const") { if (type->str() == "<" && type->link()) { if (container->type_templateArgNo >= 0) { const Token *templateType = type->next(); diff --git a/test/testclass.cpp b/test/testclass.cpp index 3c9adee8a..1ce57288d 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -193,6 +193,7 @@ private: TEST_CASE(const74); // ticket #10671 TEST_CASE(const75); // ticket #10065 TEST_CASE(const76); // ticket #10825 + TEST_CASE(const77); // ticket #10307 TEST_CASE(const_handleDefaultParameters); TEST_CASE(const_passThisToMemberOfOtherClass); TEST_CASE(assigningPointerToPointerIsNotAConstOperation); @@ -6031,6 +6032,15 @@ private: errout.str()); } + void const77() { // #10307 + checkConst("template \n" + "struct S {\n" + " std::vector const* f() const { return p; }\n" + " std::vector const* p;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void const_handleDefaultParameters() { checkConst("struct Foo {\n" " void foo1(int i, int j = 0) {\n" diff --git a/test/testother.cpp b/test/testother.cpp index 2a8e82ebe..d863bbe75 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2978,6 +2978,12 @@ private: " return *p;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #10471 + check("void f(std::array const& i) {\n" + " if (i[0] == 0) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void switchRedundantAssignmentTest() {