Skip to content

Commit fdc7691

Browse files
autoantwortclaude
andcommitted
Fix #15062 Wrong varid for shadowed member in initializer list after braced init list argument (FP uninitMemberVar, selfInitialization, functionStatic)
In setVarIdPass1 a '{' inside a constructor initializer list was only recognized as part of an argument if it was preceded by a name, '>', '>>' or '('. A braced init list that is not the first argument, e.g. x(f(0, {0})), or a nested one, e.g. x(f(0, {{1}, 2})), was treated as the start of the constructor body. As a result the parameter scope was not left correctly, so the member in a following p(p) got the varid of the parameter, and the parameter varid leaked into later functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8bb772d commit fdc7691

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎lib/tokenize.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4835,7 +4835,7 @@ void Tokenizer::setVarIdPass1()
48354835

48364836
// parse anonymous namespaces as part of the current scope
48374837
if (!Token::Match(startToken->previous(), "union|struct|enum|namespace {") &&
4838-
!(initlist && Token::Match(startToken->previous(), "%name%|>|>>|(") && Token::Match(startToken->link(), "} ,|{|)|..."))) {
4838+
!(initlist && Token::Match(startToken->previous(), "%name%|>|>>|(|,|{") && Token::Match(startToken->link(), "} ,|{|)|}|..."))) {
48394839

48404840
if (tok->str() == "{") {
48414841
bool isExecutable;

‎test/testvarid.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,30 @@ class TestVarID : public TestFixture {
27152715
"10: D < T ... > d@2 ;\n"
27162716
"11: } ;\n",
27172717
tokenize(code13));
2718+
2719+
const char code14[] = "struct S {\n" // #15062
2720+
" int x;\n"
2721+
" int* p;\n"
2722+
" S(int* p) : x(f(0, {0})), p(p) {}\n"
2723+
" S(int* p, int) : x(f(0, {{1}, 2})), p(p) {}\n"
2724+
"};\n"
2725+
"struct T {\n"
2726+
" int* p;\n"
2727+
" int g();\n"
2728+
"};\n"
2729+
"int T::g() { return *p; }\n";
2730+
ASSERT_EQUALS("1: struct S {\n"
2731+
"2: int x@1 ;\n"
2732+
"3: int * p@2 ;\n"
2733+
"4: S ( int * p@3 ) : x@1 ( f ( 0 , { 0 } ) ) , p@2 ( p@3 ) { }\n"
2734+
"5: S ( int * p@4 , int ) : x@1 ( f ( 0 , { { 1 } , 2 } ) ) , p@2 ( p@4 ) { }\n"
2735+
"6: } ;\n"
2736+
"7: struct T {\n"
2737+
"8: int * p@5 ;\n"
2738+
"9: int g ( ) ;\n"
2739+
"10: } ;\n"
2740+
"11: int T :: g ( ) { return * p@5 ; }\n",
2741+
tokenize(code14));
27182742
}
27192743

27202744
void varid_initListWithBaseTemplate() {

0 commit comments

Comments
 (0)