Treat "class" keyword similar to "struct" or "union" on C++ code (#6696)

This commit is contained in:
PKEuS 2015-11-10 17:03:27 +01:00
parent cc9a1f4375
commit 03d52de74b
2 changed files with 20 additions and 1 deletions

View File

@ -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()) {

View File

@ -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"