diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 58675bbad..7434189d4 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1593,7 +1593,7 @@ void CheckOther::checkConstPointer() if (nonConstPointers.find(p) == nonConstPointers.end()) { const Token *start = (p->isArgument()) ? p->scope()->bodyStart : p->nameToken()->next(); const int indirect = p->isArray() ? p->dimensions().size() : 1; - if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP())) + if (p->isStatic() || isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP())) continue; constVariableError(p, nullptr); } diff --git a/test/testother.cpp b/test/testother.cpp index 5ce81fa12..2a8e82ebe 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2971,6 +2971,13 @@ private: " istr >> x[0];\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #10744 + check("S& f() {\n" + " static S * p = new S();\n" + " return *p;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void switchRedundantAssignmentTest() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 13184d35e..5a7b0ec44 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2206,6 +2206,19 @@ private: "} ;", tokenizeAndStringify(code)); } + + { + // Ticket #9515 + const char code[] = "void(a)(void) {\n" + " static int b;\n" + " if (b) {}\n" + "}\n"; + ASSERT_EQUALS("void ( a ) ( void ) {\n" + "static int b ;\n" + "if ( b ) { }\n" + "}", + tokenizeAndStringify(code)); + } } void vardecl6() {