From 99f7f88f39e3c2780abe029e3c39fcd7ae88ddb4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 27 Jul 2023 20:54:12 +0200 Subject: [PATCH] Fix FN constParameterPointer (#5270) Co-authored-by: chrchr-github --- lib/astutils.cpp | 2 +- test/testother.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 3652eefbe..94307ab27 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2196,7 +2196,7 @@ T* getTokenArgumentFunctionImpl(T* tok, int& argn) parent = parent->astParent(); // passing variable to subfunction? - if (Token::Match(parent, "[(,{]")) + if (Token::Match(parent, "[[(,{]")) ; else if (Token::simpleMatch(parent, ":")) { while (Token::Match(parent, "[?:]")) diff --git a/test/testother.cpp b/test/testother.cpp index 91d1beef5..3a366df44 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3754,6 +3754,13 @@ private: " p = q;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S { int a[1]; };\n" + "void f(S* s) {\n" + " if (s->a[0]) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n", + errout.str()); } void switchRedundantAssignmentTest() {