Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
continue;
}

// Skip '='
if (tok && tok->str() == "=")
// Skip '=', '?', ':'
if (tok && Token::Match(tok, "=|?|:"))
tok = tok->next();
if (!tok)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4862,7 +4862,7 @@ bool Tokenizer::simplifyConstTernaryOp()

else if (endTok->str() == "?")
++ternaryOplevel;
else if (Token::Match(endTok, ")|}|]|;|,|:")) {
else if (Token::Match(endTok, ")|}|]|;|,|:|>")) {
if (endTok->str() == ":" && ternaryOplevel)
--ternaryOplevel;
else {
Expand Down
15 changes: 15 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(simplify_constants3);
TEST_CASE(simplify_constants4);
TEST_CASE(simplify_constants5);
TEST_CASE(simplify_constants6); // Ticket #5625: Ternary operator as template parameter
TEST_CASE(simplify_null);
TEST_CASE(simplifyMulAndParens); // Ticket #2784 + #3184

Expand Down Expand Up @@ -3591,6 +3592,20 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("int buffer [ 10 ] ;\n\n\nx = 10 ;\ny = 10 ;", tokenizeAndStringify(code,true));
}

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"
"foo < 1 ? 0 : 2 > y ;\n"
"}";
const char exp [] = "template < class T > struct foo ;\n"
"void bar ( ) {\n"
"foo < 6 > x ;\n"
"foo < 0 > y ;\n"
"}";
ASSERT_EQUALS(exp, tokenizeAndStringify(code, true));
}

void simplify_null() {
{
const char code[] =
Expand Down