From e7ad9d4dd58d8d4d5ee2a5a4fd93bd74369843b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 13 Jan 2025 14:29:02 +0100 Subject: [PATCH 1/2] add test --- test/testunusedvar.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index e6507e7304b..95624048651 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2047,6 +2047,15 @@ class TestUnusedVar : public TestFixture { " x = y;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + // #13551 - don't crash + checkStructMemberUsage("struct S {};\n" + "void f(vector> p) {\n" + " for (auto [a, _] : p) {\n" + " if (a == 0) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void functionVariableUsage_(const char* file, int line, const char code[], bool cpp = true) { From bc44f21e856bcd0c5653db4d1f03d91ddd140784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 13 Jan 2025 14:23:54 +0100 Subject: [PATCH 2/2] fix #13551 --- lib/checkunusedvar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index ca91679c17a..ba5fee3acd2 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1555,7 +1555,7 @@ void CheckUnusedVar::checkStructMemberUsage() tok = tok->next()->astOperand2(); const ValueType *valueType = tok->valueType(); - if (!valueType->containerTypeToken) + if (!valueType || !valueType->containerTypeToken) continue; const Type *type = valueType->containerTypeToken->type();