From 042c6e7d8826f41c669484239793f1d81fcf0b0b Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 2 Apr 2023 21:06:17 -0500 Subject: [PATCH 1/2] Fix 11578: FP accessMoved with range-based for loop --- lib/forwardanalyzer.cpp | 2 +- test/testother.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 562b1206b3d..dfbfcd2163a 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -413,7 +413,7 @@ struct ForwardTraversal { return Break(); if (stepTok && updateRecursive(stepTok) == Progress::Break) return Break(); - if (condTok && updateRecursive(condTok) == Progress::Break) + if (condTok && !Token::simpleMatch(condTok, ":") && updateRecursive(condTok) == Progress::Break) return Break(); return Progress::Continue; } diff --git a/test/testother.cpp b/test/testother.cpp index f3679d08007..2be0ebcbbfe 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -266,6 +266,7 @@ class TestOther : public TestFixture { TEST_CASE(moveClassVariable); TEST_CASE(forwardAndUsed); TEST_CASE(moveAndReference); + TEST_CASE(moveForRange); TEST_CASE(funcArgNamesDifferent); TEST_CASE(funcArgOrderDifferent); @@ -10300,6 +10301,18 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:7]: (warning) Access of moved variable 'r'.\n", errout.str()); } + void moveForRange() + { + check("struct C {\n" + " void f() {\n" + " for (auto r : mCategory.find(std::move(mWhere))) {}\n" + " }\n" + " cif::category mCategory;\n" + " cif::condition mWhere;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void funcArgNamesDifferent() { check("void func1(int a, int b, int c);\n" "void func1(int a, int b, int c) { }\n" From e7910f9c95511a1fc6d00f159c23190a8482abd3 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 2 Apr 2023 21:06:54 -0500 Subject: [PATCH 2/2] Format --- test/testother.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 2be0ebcbbfe..7a96cf474ff 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10304,12 +10304,12 @@ class TestOther : public TestFixture { void moveForRange() { check("struct C {\n" - " void f() {\n" - " for (auto r : mCategory.find(std::move(mWhere))) {}\n" - " }\n" - " cif::category mCategory;\n" - " cif::condition mWhere;\n" - "};\n"); + " void f() {\n" + " for (auto r : mCategory.find(std::move(mWhere))) {}\n" + " }\n" + " cif::category mCategory;\n" + " cif::condition mWhere;\n" + "};\n"); ASSERT_EQUALS("", errout.str()); }