From c58d02f1460bc7faf7dc2f9f31c22bbc16414b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Apr 2012 18:23:12 +0200 Subject: [PATCH] Tokenizer::setVarIdNew: in C code, allow that variable declaration starts with delete and throw --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e91e06475..2956fe17d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 751a71072..d0d357a26 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"