From 2627aada07eb30256f7330763a10864726782cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Jan 2016 08:28:04 +0100 Subject: [PATCH] Fixed #7346 (Tokenizer::setVarId: No varId for member in initialization list) --- lib/tokenize.cpp | 4 +++- test/testvarid.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2eac7effc..3d7e3ec69 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2969,10 +2969,12 @@ void Tokenizer::setVarId() tok2 = tok2->linkAt(2); // constructor with initializer list - if (Token::Match(tok2, ") : %name%")) { + if (Token::Match(tok2, ") : ::| %name%")) { Token *tok3 = tok2; while (Token::Match(tok3, "[)}] [,:]")) { tok3 = tok3->tokAt(2); + if (Token::Match(tok3, ":: %name%")) + tok3 = tok3->next(); while (Token::Match(tok3, "%name% :: %name%")) tok3 = tok3->tokAt(2); if (!Token::Match(tok3, "%name% (|{|<")) diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 015833354..1e0995e8d 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -166,6 +166,7 @@ private: TEST_CASE(varidclass16); // #4577 TEST_CASE(varidclass17); // #6073 TEST_CASE(varidclass18); + TEST_CASE(varidclass19); // initializer list TEST_CASE(varid_classnameshaddowsvariablename); // #3990 TEST_CASE(varidnamespace1); @@ -2845,6 +2846,21 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } + void varidclass19() { + const char code[] = "class A : public ::B {\n" + " int a;\n" + " A();\n" + "};\n" + "A::A() : ::B(), a(0) {}"; + const char expected[] = "\n\n##file 0\n" + "1: class A : public :: B {\n" + "2: int a@1 ;\n" + "3: A ( ) ;\n" + "4: } ;\n" + "5: A :: A ( ) : :: B ( ) , a@1 ( 0 ) { }\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + void varid_classnameshaddowsvariablename() { const char code[] = "class Data;\n" "void strange_declarated(const Data& Data);\n"