From a0e5fad6a9caf94b6c9c9d3ea8c595cbccd4309e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 15 May 2012 07:17:31 +0200 Subject: [PATCH] Fixed #3776 (Tokenizer::setVarId: No varid set when unknown macro is used before variable declaration) --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index dd500c1be..05a82a3dd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2677,7 +2677,8 @@ void Tokenizer::setVarId() } if (tok == list.front() || Token::Match(tok, "[;{}]") || - (Token::Match(tok,"[(,]") && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {")))) { + (Token::Match(tok,"[(,]") && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {"))) || + (tok->isName() && tok->str().at(tok->str().length()-1U) == ':')) { // locate the variable name.. const Token *tok2 = (tok->isName()) ? tok : tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a643dcaf7..fd9df57c7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -231,6 +231,7 @@ private: TEST_CASE(varid_in_class5); // #3584 - std::vector<::FOO::B> b; TEST_CASE(varid_in_class6); // #3755 TEST_CASE(varid_in_class7); // set variable id for struct members + TEST_CASE(varid_in_class8); // unknown macro in class TEST_CASE(varid_operator); TEST_CASE(varid_throw); TEST_CASE(varid_unknown_macro); // #2638 - unknown macro is not type @@ -3618,6 +3619,21 @@ private: tokenizeDebugListing(code)); } + void varid_in_class8() { // #3776 - unknown macro + const char code[] = "class A {\n" + " UNKNOWN_MACRO(A)\n" + "private:\n" + " int x;\n" + "};"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: class A {\n" + "2: UNKNOWN_MACRO ( A )\n" + "3: private:\n" + "4: int x@1 ;\n" + "5: } ;\n", + tokenizeDebugListing(code)); + } + void varid_operator() { { const std::string actual = tokenizeDebugListing(