diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7a3ccb5dc..96bde3089 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3409,12 +3409,17 @@ void Tokenizer::setVarId() if (tok->str() == "virtual") continue; - if (tok->str() == "unsigned") - tok = tok->next(); - if (Token::Match(tok, "class|struct|union %type% :|{|;")) continue; + while (Token::Match(tok, "public:|private:|protected:")) + tok = tok->next(); + if (!tok) + break; + + if (tok->str() == "unsigned") + tok = tok->next(); + if (Token::Match(tok, "using namespace %type% ;")) { tok = tok->next(); continue; @@ -3426,12 +3431,15 @@ void Tokenizer::setVarId() if (Token::Match(tok, "else|return|typedef|delete|sizeof")) continue; - while (Token::Match(tok, "const|static|extern|public:|private:|protected:|;|mutable")) + while (Token::Match(tok, "const|static|extern|;|mutable")) tok = tok->next(); if (tok && tok->str() == "friend") continue; + if (Token::Match(tok, "struct %type%")) + tok = tok->next(); + // skip global namespace prefix if (Token::simpleMatch(tok, "::")) tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 53edab142..abe0a7182 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -190,6 +190,7 @@ private: TEST_CASE(varid39); // ticket #3279 (varid for 'FOO::BAR const') TEST_CASE(varid40); // ticket #3279 TEST_CASE(varid41); // ticket #3340 (varid for union type) + TEST_CASE(varid42); // ticket #3316 (varid for array) TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); @@ -3029,6 +3030,21 @@ private: "1: struct evt ; void f ( const evt & event@1 ) ;\n", tokenizeDebugListing(code2)); } + + void varid42() { + const std::string code("namespace fruit { struct banana {}; };\n" + "class Fred {\n" + "public:\n" + " struct fruit::banana Bananas[25];\n" + "};"); + ASSERT_EQUALS("\n\n##file 0\n" + "1: namespace fruit { struct banana { } ; } ;\n" + "2: class Fred {\n" + "3: public:\n" + "4: struct fruit :: banana Bananas@1 [ 25 ] ;\n" + "5: } ;\n", + tokenizeDebugListing(code)); + } void varidFunctionCall1() { const std::string code("void f() {\n"