Tokenizer::setVarIdNew: in C code, allow that variable declaration starts with delete and throw

This commit is contained in:
Daniel Marjamäki 2012-04-15 18:23:12 +02:00
parent ea148173bb
commit c58d02f146
2 changed files with 17 additions and 1 deletions

View File

@ -2912,7 +2912,7 @@ void Tokenizer::setVarIdNew()
// Variable declaration can't start with "return", etc
if (tok2->str() == "return" || tok2->str() == "NOT" || tok2->str() == "goto" ||
tok2->str() == "delete" || tok2->str() == "throw")
(!isC() && (tok2->str() == "delete" || tok2->str() == "throw")))
continue;
const bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top());

View File

@ -208,6 +208,7 @@ private:
TEST_CASE(varid42); // ticket #3316 (varid for array)
TEST_CASE(varid43);
TEST_CASE(varid44);
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
TEST_CASE(varidFunctionCall3);
@ -3266,6 +3267,21 @@ private:
tokenizeDebugListing(code));
}
void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n"
" delete d;\n"
" throw t;\n"
"}";
const char expected[] = "\n\n##file 0\n"
"1: void f ( ) {\n"
"2: delete d@1 ;\n"
"3: throw t@2 ;\n"
"4: }\n";
ASSERT_EQUALS(expected, tokenizeDebugListing(code,false,"test.c"));
}
void varidFunctionCall1() {
const std::string code("void f() {\n"
" int x;\n"