diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 399c4ab2d..5627488d2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4399,6 +4399,10 @@ bool Tokenizer::simplifyConstTernaryOp() if (!semicolon || semicolon->previous()->str() != ":" || !semicolon->next()) continue; + //handle the GNU extension: "x ? : y" <-> "x ? x : y" + if (semicolon->previous() == tok->next()) + tok->insertToken(tok->strAt(-offset)); + // go back before the condition, if possible tok = tok->tokAt(-2); if (offset == 2) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 4ffc41c39..aea306c88 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2122,7 +2122,7 @@ private: const char actual[] = "template < int n > struct B { int a [ n ] ; } ; " "bitset<1> z ; " - "class bitset<1> : B < ( ) > { }"; + "class bitset<1> : B < 4 > { }"; const char expected[] = "bitset<1> z ; " "class bitset<1> : B<4> { } " @@ -2814,6 +2814,12 @@ private: ASSERT_EQUALS("= 0 ;", tok(code)); } + //GNU extension: "x ?: y" <-> "x ? x : y" + { + const char code[] = "; a = 1 ? : x; b = 0 ? : 2;"; + ASSERT_EQUALS("; a = 1 ; b = 2 ;", tok(code)); + } + { const char code[] = "int f(int b, int d)\n" "{\n"