diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 88709a884..d0522df68 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -452,9 +452,7 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[]) // Remove "volatile" while (Token::simpleMatch(_tokens, "volatile")) { - Token *tok = _tokens; - _tokens = _tokens->next(); - delete tok; + _tokens->deleteThis(); } for (Token *tok = _tokens; tok; tok = tok->next()) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ac2f89c07..80b8984e5 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -130,6 +130,7 @@ private: TEST_CASE(vardecl1); TEST_CASE(vardecl2); + TEST_CASE(volatile_variables); } @@ -1413,6 +1414,17 @@ private: ASSERT_EQUALS("void foo ( a , b ) unsigned int a ; unsigned int b ; { }", actual); } + + void volatile_variables() + { + const char code[] = "volatile int a=0;\n" + "volatile int b=0;\n" + "volatile int c=0;\n"; + + const std::string actual(tokenizeAndStringify(code)); + + ASSERT_EQUALS("int a ; a = 0 ;\nint b ; b = 0 ;\nint c ; c = 0 ;", actual); + } }; REGISTER_TEST(TestTokenizer)