Tokenizer::simplifyConstTernaryOp: Properly detect the end of the 'false' part of ternary operators when it contains '>'.
This commit is contained in:
parent
b96f4f53ad
commit
70561682eb
|
@ -4823,8 +4823,12 @@ bool Tokenizer::simplifyConstTernaryOp()
|
|||
|
||||
const int offset = (tok->previous()->str() == ")") ? 2 : 1;
|
||||
|
||||
if (tok->strAt(-2*offset) == "<" && !TemplateSimplifier::templateParameters(tok->tokAt(-2*offset)))
|
||||
bool inTemplateParameter = false;
|
||||
if (tok->strAt(-2*offset) == "<") {
|
||||
if (!TemplateSimplifier::templateParameters(tok->tokAt(-2*offset)))
|
||||
continue;
|
||||
inTemplateParameter = true;
|
||||
}
|
||||
|
||||
// Find the token ":" then go to the next token
|
||||
Token *semicolon = skipTernaryOp(tok);
|
||||
|
@ -4869,6 +4873,8 @@ bool Tokenizer::simplifyConstTernaryOp()
|
|||
else if (Token::Match(endTok, ")|}|]|;|,|:|>")) {
|
||||
if (endTok->str() == ":" && ternaryOplevel)
|
||||
--ternaryOplevel;
|
||||
else if (endTok->str() == ">" && !inTemplateParameter)
|
||||
;
|
||||
else {
|
||||
Token::eraseTokens(semicolon->tokAt(-2), endTok);
|
||||
ret = true;
|
||||
|
|
|
@ -3599,6 +3599,7 @@ private:
|
|||
}
|
||||
|
||||
void simplify_constants6() { // Ticket #5625
|
||||
{
|
||||
const char code[] = "template < class T > struct foo ;\n"
|
||||
"void bar ( ) {\n"
|
||||
"foo < 1 ? 0 ? 1 : 6 : 2 > x ;\n"
|
||||
|
@ -3611,6 +3612,12 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS(exp, tokenizeAndStringify(code, true));
|
||||
}
|
||||
{
|
||||
const char code[] = "bool b = true ? false : 1 > 2 ;";
|
||||
const char exp [] = "bool b ; b = false ;";
|
||||
ASSERT_EQUALS(exp, tokenizeAndStringify(code, true));
|
||||
}
|
||||
}
|
||||
|
||||
void simplify_null() {
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue