Fix #11334 debug: varid0 with anonymous union (#5648)

This commit is contained in:
chrchr-github 2023-11-11 10:01:03 +01:00 committed by GitHub
parent 282c195a6f
commit 328daeceb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -5130,7 +5130,7 @@ void Tokenizer::setVarIdPass2()
continue;
}
}
if (tok2->str() == "{") {
if (tok2->str() == "{" && !Token::simpleMatch(tok2->previous(), "union")) {
if (tok2->strAt(-1) == ")")
setVarIdClassFunction(scopeName2 + classname, tok2, tok2->link(), thisClassVars, structMembers, mVarId);
tok2 = tok2->link();

View File

@ -141,6 +141,7 @@ private:
TEST_CASE(varid_in_class23); // #11293
TEST_CASE(varid_in_class24);
TEST_CASE(varid_in_class25);
TEST_CASE(varid_in_class26);
TEST_CASE(varid_namespace_1); // #7272
TEST_CASE(varid_namespace_2); // #7000
TEST_CASE(varid_namespace_3); // #8627
@ -2102,6 +2103,31 @@ private:
ASSERT_EQUALS(expected, tokenize(code, "test.cpp", &s));
}
void varid_in_class26() {
const char *code{}, *expected{}; // #11334
code = "struct S {\n"
" union {\n"
" uint8_t u8[4];\n"
" uint32_t u32;\n"
" };\n"
" void f();\n"
"};\n"
"void S::f() {\n"
" u8[0] = 0;\n"
"}\n";
expected = "1: struct S {\n"
"2: union {\n"
"3: uint8_t u8@1 [ 4 ] ;\n"
"4: uint32_t u32@2 ;\n"
"5: } ;\n"
"6: void f ( ) ;\n"
"7: } ;\n"
"8: void S :: f ( ) {\n"
"9: u8@1 [ 0 ] = 0 ;\n"
"10: }\n";
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
}
void varid_namespace_1() { // #7272
const char code[] = "namespace Blah {\n"
" struct foo { int x;};\n"