File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4155,6 +4155,17 @@ class TestOther : public TestFixture {
41554155 " return r;\n"
41564156 "}\n");
41574157 ASSERT_EQUALS("", errout_str());
4158+
4159+ check("struct Item { int state; };\n"
4160+ "void foo(std::vector<Item> &items) {\n"
4161+ " for (auto &item : items) {\n"
4162+ " switch (auto &s = item.state) {\n"
4163+ " case 0: s = 1; break;\n"
4164+ " default: break;\n"
4165+ " }\n"
4166+ " }\n"
4167+ "}\n");
4168+ ASSERT_EQUALS("", errout_str());
41584169 }
41594170
41604171 void constParameterCallback() {
Original file line number Diff line number Diff line change @@ -204,6 +204,7 @@ class TestSymbolDatabase : public TestFixture {
204204 TEST_CASE(isVariableDeclarationRValueRef);
205205 TEST_CASE(isVariableDeclarationDoesNotIdentifyCase);
206206 TEST_CASE(isVariableDeclarationIf);
207+ TEST_CASE(isVariableDeclarationSwitch);
207208 TEST_CASE(isVariableStlType);
208209 TEST_CASE(isVariablePointerToConstPointer);
209210 TEST_CASE(isVariablePointerToVolatilePointer);
@@ -1234,6 +1235,22 @@ class TestSymbolDatabase : public TestFixture {
12341235 ASSERT(y->variable());
12351236 }
12361237
1238+ void isVariableDeclarationSwitch() {
1239+ GET_SYMBOL_DB("struct Item { int state; };\n"
1240+ "void foo(std::vector<Item> &items) {\n"
1241+ " for (auto &item : items) {\n"
1242+ " switch (auto &s = item.state) {\n"
1243+ " case 0: s = 1; break;\n"
1244+ " default: break;\n"
1245+ " }\n"
1246+ " }\n"
1247+ "}\n");
1248+ const Token *s = Token::findsimplematch(tokenizer.tokens(), "s");
1249+ ASSERT(s);
1250+ ASSERT(s->varId());
1251+ ASSERT(s->variable());
1252+ }
1253+
12371254 void VariableValueType1() {
12381255 GET_SYMBOL_DB("typedef uint8_t u8;\n"
12391256 "static u8 x;");
You can’t perform that action at this time.
0 commit comments