Skip to content

Commit 746b3a7

Browse files
authored
Fix #15062 Wrong varid for shadowed member in initializer list after braced init list argument (FP uninitMemberVar, selfInitialization, functionStatic) (#8885)
1 parent 7449640 commit 746b3a7

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
@@ -4842,7 +4842,7 @@ void Tokenizer::setVarIdPass1()
48424842

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

48474847
if (tok->str() == "{") {
48484848
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)