Support GNU extension of '?:' operator:
"x ? : y" is equivalent to "x ? x : y". I found a lot of code with this extension, probably we should warn a user to not use this.
This commit is contained in:
parent
9556634ee7
commit
119ab519a4
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue