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;
|
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;
|
continue;
|
||||||
|
inTemplateParameter = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the token ":" then go to the next token
|
// Find the token ":" then go to the next token
|
||||||
Token *semicolon = skipTernaryOp(tok);
|
Token *semicolon = skipTernaryOp(tok);
|
||||||
|
@ -4869,6 +4873,8 @@ bool Tokenizer::simplifyConstTernaryOp()
|
||||||
else if (Token::Match(endTok, ")|}|]|;|,|:|>")) {
|
else if (Token::Match(endTok, ")|}|]|;|,|:|>")) {
|
||||||
if (endTok->str() == ":" && ternaryOplevel)
|
if (endTok->str() == ":" && ternaryOplevel)
|
||||||
--ternaryOplevel;
|
--ternaryOplevel;
|
||||||
|
else if (endTok->str() == ">" && !inTemplateParameter)
|
||||||
|
;
|
||||||
else {
|
else {
|
||||||
Token::eraseTokens(semicolon->tokAt(-2), endTok);
|
Token::eraseTokens(semicolon->tokAt(-2), endTok);
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
|
@ -3599,6 +3599,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplify_constants6() { // Ticket #5625
|
void simplify_constants6() { // Ticket #5625
|
||||||
|
{
|
||||||
const char code[] = "template < class T > struct foo ;\n"
|
const char code[] = "template < class T > struct foo ;\n"
|
||||||
"void bar ( ) {\n"
|
"void bar ( ) {\n"
|
||||||
"foo < 1 ? 0 ? 1 : 6 : 2 > x ;\n"
|
"foo < 1 ? 0 ? 1 : 6 : 2 > x ;\n"
|
||||||
|
@ -3611,6 +3612,12 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(exp, tokenizeAndStringify(code, true));
|
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() {
|
void simplify_null() {
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue