File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -246,8 +246,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
246246 continue ;
247247 }
248248
249- // Skip '='
250- if (tok && tok-> str () == " = " )
249+ // Skip '=', '?', ':'
250+ if (tok && Token::Match (tok, " =|?|: " ) )
251251 tok = tok->next ();
252252 if (!tok)
253253 return 0 ;
Original file line number Diff line number Diff line change @@ -4862,7 +4862,7 @@ bool Tokenizer::simplifyConstTernaryOp()
48624862
48634863 else if (endTok->str () == " ?" )
48644864 ++ternaryOplevel;
4865- else if (Token::Match (endTok, " )|}|]|;|,|:" )) {
4865+ else if (Token::Match (endTok, " )|}|]|;|,|:|> " )) {
48664866 if (endTok->str () == " :" && ternaryOplevel)
48674867 --ternaryOplevel;
48684868 else {
Original file line number Diff line number Diff line change @@ -254,6 +254,7 @@ class TestTokenizer : public TestFixture {
254254 TEST_CASE (simplify_constants3);
255255 TEST_CASE (simplify_constants4);
256256 TEST_CASE (simplify_constants5);
257+ TEST_CASE (simplify_constants6); // Ticket #5625: Ternary operator as template parameter
257258 TEST_CASE (simplify_null);
258259 TEST_CASE (simplifyMulAndParens); // Ticket #2784 + #3184
259260
@@ -3591,6 +3592,20 @@ class TestTokenizer : public TestFixture {
35913592 ASSERT_EQUALS (" int buffer [ 10 ] ;\n\n\n x = 10 ;\n y = 10 ;" , tokenizeAndStringify (code,true ));
35923593 }
35933594
3595+ void simplify_constants6 () { // Ticket #5625
3596+ const char code[] = " template < class T > struct foo ;\n "
3597+ " void bar ( ) {\n "
3598+ " foo < 1 ? 0 ? 1 : 6 : 2 > x ;\n "
3599+ " foo < 1 ? 0 : 2 > y ;\n "
3600+ " }" ;
3601+ const char exp [] = " template < class T > struct foo ;\n "
3602+ " void bar ( ) {\n "
3603+ " foo < 6 > x ;\n "
3604+ " foo < 0 > y ;\n "
3605+ " }" ;
3606+ ASSERT_EQUALS (exp, tokenizeAndStringify (code, true ));
3607+ }
3608+
35943609 void simplify_null () {
35953610 {
35963611 const char code[] =
You can’t perform that action at this time.
0 commit comments