From b049050792351604b328c13c62324d280e241fc0 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 2 Nov 2015 22:14:41 +0100 Subject: [PATCH] Fixed wrong parsing of ^{} --- lib/tokenize.cpp | 7 +++---- test/testgarbage.cpp | 8 +++++--- test/testsimplifytemplate.cpp | 2 +- test/testtokenize.cpp | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1207dc40d..593cbc488 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9294,9 +9294,7 @@ void Tokenizer::simplifyAsm2() for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "^ {")) { Token * start = tok; - while (start && !Token::Match(start, "[;{}]")) { - if (start->link() && Token::Match(start, ")|]")) - start = start->link(); + while (start && !Token::Match(start, "[;{})]")) { start = start->previous(); } if (start) @@ -9304,8 +9302,9 @@ void Tokenizer::simplifyAsm2() const Token *last = tok->next()->link(); if (start != tok) { last = last->next(); - while (last && !Token::Match(last->next(), "[;{}()]")) + while (last && !Token::Match(last->next(), "[;{})]")) last = last->next(); + last = last->next(); } if (start && last) { std::string asmcode(start->str()); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index c45639272..bf99a4847 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -657,8 +657,8 @@ private: } void garbageCode58() { // #6732, #6762 - ASSERT_THROW(checkCode("{ }> {= ~A()^{} }P { }"), InternalError); - ASSERT_THROW(checkCode("{= ~A()^{} }P { } { }> is"), InternalError); + checkCode("{ }> {= ~A()^{} }P { }"); + checkCode("{= ~A()^{} }P { } { }> is"); } void garbageCode59() { // #6735 @@ -782,7 +782,7 @@ private: } void garbageCode89() { // #6772 - ASSERT_THROW(checkCode("{ { ( ) } P ( ) ^ { } { } { } ( ) } 0"), InternalError); // do not crash + checkCode("{ { ( ) } P ( ) ^ { } { } { } ( ) } 0"); // do not crash } void garbageCode90() { // #6790 @@ -1164,6 +1164,8 @@ private: " for (int ui = 0; ui < 1z; ui++)\n" " ;\n" "}"); + + checkCode("; void f ^ { return } int main ( ) { }"); // #4941 } void garbageValueFlow() { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 640d334f9..ddb2cc5dc 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -810,7 +810,7 @@ private: " return sizeof...(args);\n" " }();\n" "}"; - ASSERT_THROW(tok(code), InternalError); + tok(code); } void template43() { // #5097 - Assert due to '>>' in 'B>' not being treated as end of template instantation diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2012c37d2..7e1f2f2f1 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -775,8 +775,20 @@ private: // #4725 - ^{} void tokenize28() { ASSERT_EQUALS("void f ( ) { asm ( \"^{}\" ) ; }", tokenizeAndStringify("void f() { ^{} }")); - ASSERT_EQUALS("void f ( ) { asm ( \"x(^{})\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }")); - ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }")); + ASSERT_EQUALS("void f ( ) { asm ( \"x(^{});\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }")); + ASSERT_EQUALS("int f0 ( Args args ) {\n" + "asm ( \"return^{returnsizeof...(Args);}()\" ) ;\n" + "\n" + "asm ( \"+^{returnsizeof...(args);}()\" ) ;\n" + "\n" + "\n" + "} ;", tokenizeAndStringify("int f0(Args args) {\n" + " return ^{\n" + " return sizeof...(Args);\n" + " }() + ^ {\n" + " return sizeof...(args);\n" + " }();\n" + "};")); } // #3503 - don't "simplify" SetFunction member function to a variable