From 6ba512d1d1af17c941934f20aaacda58a07388f6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:07:11 +0100 Subject: [PATCH 1/3] Update astutils.cpp --- lib/astutils.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index d5d38bc3453..c91f41d9651 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2943,6 +2943,9 @@ static bool isExpressionChangedAt(const F& getExprTok, auto expr = getExprTok(); if (!expr && !(tok->valueType() && tok->valueType()->pointer == 0 && tok->valueType()->reference == Reference::None)) aliased = true; + if (!aliased && expr && expr->varId() && tok->isCast() && tok->valueType() && tok->valueType()->reference != Reference::None && + Token::Match(tok->astOperand2() ? tok->astOperand2() : tok->astOperand1(), "%varid%", expr->varId())) + aliased = true; if (!aliased) aliased = isAliasOf(tok, expr, &i); if (!aliased) From 81c113e1a43b08dff39780aab0da498cadbcf834 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:08:49 +0100 Subject: [PATCH 2/3] Update testother.cpp --- test/testother.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 6b1ae634d26..8251aec99ca 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3981,6 +3981,19 @@ class TestOther : public TestFixture { " t.s->i = 0;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct B {};\n" // #13877 + "struct D : B { int i; };\n" + "void f(B& b) {\n" + " static_cast(b).i = 0;\n" + "}\n" + "void g(B& b) {\n" + " std::cin >> static_cast(b).i;\n" + "}\n" + "int h(B& b) {\n" + " return static_cast(b).i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:9:10]: (style) Parameter 'b' can be declared as reference to const [constParameterReference]\n", errout_str()); } void constParameterCallback() { From 577e275b181036afa46bcca62393b72b1591c4c8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:12:27 +0100 Subject: [PATCH 3/3] Update testother.cpp --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 8251aec99ca..c4efdc2c611 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3988,7 +3988,7 @@ class TestOther : public TestFixture { " static_cast(b).i = 0;\n" "}\n" "void g(B& b) {\n" - " std::cin >> static_cast(b).i;\n" + " std::cin >> static_cast(b).i;\n" "}\n" "int h(B& b) {\n" " return static_cast(b).i;\n"