diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c37919efa..1e31aa14f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3398,7 +3398,7 @@ void Tokenizer::setVarId() if (tok->str() == "unsigned") tok = tok->next(); - if (Token::Match(tok, "class|struct %type% :|{|;")) + if (Token::Match(tok, "class|struct|union %type% :|{|;")) continue; if (Token::Match(tok, "using namespace %type% ;")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1b519f12f..373e03f3e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -189,6 +189,7 @@ private: TEST_CASE(varid38); // ticket #3272 (varid for 'FOO class C;') 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(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); @@ -3016,6 +3017,18 @@ private: tokenizeDebugListing(code)); } + void varid41() { + const std::string code1("union evt; void f(const evt & event);"); + ASSERT_EQUALS("\n\n##file 0\n" + "1: union evt ; void f ( const evt & event@1 ) ;\n", + tokenizeDebugListing(code1)); + + const std::string code2("struct evt; void f(const evt & event);"); + ASSERT_EQUALS("\n\n##file 0\n" + "1: struct evt ; void f ( const evt & event@1 ) ;\n", + tokenizeDebugListing(code2)); + } + void varidFunctionCall1() { const std::string code("void f() {\n" " int x;\n"