Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5088,7 +5088,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();
Expand Down
26 changes: 26 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class TestVarID : public TestFixture {
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
Expand Down Expand Up @@ -2102,6 +2103,31 @@ class TestVarID : public TestFixture {
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"
Expand Down