From 274fd2b9858843d81ff962eae0c5c8ab3dd6a17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 15 Jul 2011 19:37:39 +0200 Subject: [PATCH] Tokenizer: Fix minor problem with 'X&&Y' --- lib/tokenize.cpp | 8 +++++++- test/testtokenize.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2235771fd..4e0ca54f0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -425,8 +425,14 @@ void Tokenizer::createTokens(std::istream &code) // tokenize .125 into 0.125 CurrentToken = "0"; } - else if (ch=='&' && CurrentToken.empty() && code.peek() == '&') + else if (ch=='&' && code.peek() == '&') { + if (!CurrentToken.empty()) + { + addtoken(CurrentToken.c_str(), lineno, FileIndex, true); + CurrentToken.clear(); + } + // && ch = (char)code.get(); addtoken("&&", lineno, FileIndex, true); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5e133f9cf..9bb27e51d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -51,6 +51,7 @@ private: TEST_CASE(tokenize15); // tokenize ".123" TEST_CASE(tokenize16); // #2612 - segfault for "<><<" TEST_CASE(tokenize17); // #2759 + TEST_CASE(tokenize18); // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )" // don't freak out when the syntax is wrong TEST_CASE(wrong_syntax); @@ -559,6 +560,11 @@ private: ASSERT_EQUALS("class B : private :: A { } ;", tokenizeAndStringify("class B : private ::A { };")); } + void tokenize18() // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )" + { + ASSERT_EQUALS("( X && Y )", tokenizeAndStringify("(X&&Y)")); + } + void wrong_syntax() { {