diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5375c709f..f126bae84 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3389,9 +3389,6 @@ void Tokenizer::setVarId() if (tok && tok->str() == "friend") continue; - if (Token::Match(tok, "class|struct %type% ;")) - continue; - // skip global namespace prefix if (Token::simpleMatch(tok, "::")) tok = tok->next(); @@ -3497,6 +3494,9 @@ void Tokenizer::setVarId() tok2 = tok2->next(); } + if (Token::Match(tok2 ? tok2->tokAt(-2) : 0, "class|struct %type% ;")) + continue; + // End of tokens reached.. if (!tok2) break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 61a755b25..6e9440ff2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -185,6 +185,7 @@ private: TEST_CASE(varid35); // ticket #2937 TEST_CASE(varid36); // ticket #2980 (segmentation fault) TEST_CASE(varid37); // ticket #3092 (varid for 'Bar bar(*this);') + TEST_CASE(varid38); // ticket #3272 (varid for 'FOO class C;') TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); @@ -2947,6 +2948,12 @@ private: tokenizeDebugListing(code)); } + void varid38() { + const std::string code = "FOO class C;\n"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: FOO class C ;\n", + tokenizeDebugListing(code)); + } void varidFunctionCall1() { const std::string code("void f() {\n"