From df952926f83c75ab9a8f6fc10a848f8992140deb Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Wed, 20 Nov 2019 16:13:32 -0500 Subject: [PATCH] fix syntax error for a.operator++() ? a.operator--() : 0 (#2382) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6de8e5325..20e30ff3d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10815,7 +10815,7 @@ void Tokenizer::deleteSymbolDatabase() bool Tokenizer::operatorEnd(const Token * tok) const { if (tok && tok->str() == ")") { - if (isFunctionHead(tok, "{|;")) + if (isFunctionHead(tok, "{|;|?|:")) return true; tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 40447f8f3..ed9fce4fa 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -408,6 +408,7 @@ private: TEST_CASE(simplifyOperatorName21); TEST_CASE(simplifyOperatorName22); TEST_CASE(simplifyOperatorName23); + TEST_CASE(simplifyOperatorName24); TEST_CASE(simplifyNullArray); @@ -6547,6 +6548,19 @@ private: } } + void simplifyOperatorName24() { + { + const char code[] = "void foo() { int i = a.operator++() ? a.operator--() : 0; }"; + ASSERT_EQUALS("void foo ( ) { int i ; i = a . operator++ ( ) ? a . operator-- ( ) : 0 ; }", + tokenizeAndStringify(code)); + } + { + const char code[] = "void foo() { int i = a.operator++(0) ? a.operator--(0) : 0; }"; + ASSERT_EQUALS("void foo ( ) { int i ; i = a . operator++ ( 0 ) ? a . operator-- ( 0 ) : 0 ; }", + tokenizeAndStringify(code)); + } + } + void simplifyNullArray() { ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;")); }