From 5ee6c2138c1ffe8f66fecf0844944952e8de1084 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Tue, 5 Mar 2019 05:35:45 -0500 Subject: [PATCH] Fixed #9016 (tokenizer: wrong simplification for operator ^ (){}) (#1724) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 328783f87..93a5065bc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9390,7 +9390,7 @@ void Tokenizer::simplifyAsm2() if (tok->str() != "^") continue; - if (Token::simpleMatch(tok, "^ {") || Token::simpleMatch(tok->linkAt(1), ") {")) { + if (Token::simpleMatch(tok, "^ {") || (Token::simpleMatch(tok->linkAt(1), ") {") && tok->strAt(-1) != "operator")) { Token * start = tok; while (start && !Token::Match(start, "[,(;{}=]")) { if (start->link() && Token::Match(start, ")|]|>")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0be68d70b..d5d744f94 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1130,6 +1130,30 @@ private: tokenizeAndStringify("; return f(^(void){somecode});")); ASSERT_EQUALS("; asm ( \"a?(b?(c,asm(\"^{}\")):0):^{}\" ) ;", tokenizeAndStringify(";a?(b?(c,^{}):0):^{};")); + ASSERT_EQUALS("template < typename T > " + "CImg < T > operator| ( const char * const expression , const CImg < T > & img ) { " + "return img | expression ; " + "} " + "template < typename T > " + "CImg < T > operator^ ( const char * const expression , const CImg < T > & img ) { " + "return img ^ expression ; " + "} " + "template < typename T > " + "CImg < T > operator== ( const char * const expression , const CImg < T > & img ) { " + "return img == expression ; " + "}", + tokenizeAndStringify("template < typename T >" + "inline CImg operator|(const char *const expression, const CImg& img) {" + " return img | expression ;" + "}" + "template" + "inline CImg operator^(const char *const expression, const CImg& img) {" + " return img ^ expression;" + "}" + "template" + "inline CImg operator==(const char *const expression, const CImg& img) {" + " return img == expression;" + "}")); } void ifAddBraces1() {