diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fc3a482c5..dbbf105d1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2844,7 +2844,7 @@ void Tokenizer::setVarId() if (tok->isName()) { // don't set variable id after a struct|enum|union - if (Token::Match(tok->previous(), "struct|enum|union")) + if (Token::Match(tok->previous(), "struct|enum|union") || (isCPP() && tok->strAt(-1) == "class")) continue; if (!isC()) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 38b16c7f2..b5404627b 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -88,6 +88,7 @@ private: TEST_CASE(varid56); // function with a throw() TEST_CASE(varid57); // #6636: new scope by {} TEST_CASE(varid58); // #6638: for loop in for condition + TEST_CASE(varid59); // #6696 TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete" TEST_CASE(varidFunctionCall1); @@ -1058,6 +1059,24 @@ private: ASSERT_EQUALS(expected1, tokenize(code1, false, "test.cpp")); } + void varid59() { // #6696 + const char code[] = "class DLLSYM B;\n" + "struct B {\n" + " ~B() {}\n" + "};"; + const char expected[] = "\n\n##file 0\n" + "1: class DLLSYM B@1 ;\n" // In this line, we cannot really do better... + "2: struct B {\n" + "3: ~ B@1 ( ) { }\n" // ...but here we could + "4: } ;\n"; + const char wanted[] = "\n\n##file 0\n" + "1: class DLLSYM B@1 ;\n" + "2: struct B {\n" + "3: ~ B ( ) { }\n" + "4: } ;\n";; + TODO_ASSERT_EQUALS(wanted, expected, tokenize(code, false, "test.cpp")); + } + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n"