Fixed #7471 (Tokenizer::prepareTernaryOpForAST: typedef with comma inside ?:)

This commit is contained in:
Daniel Marjamäki 2016-05-22 11:33:21 +02:00
parent b7b92b2140
commit 06d5e73e88
2 changed files with 7 additions and 0 deletions

View File

@ -3530,6 +3530,11 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
simplifyTypedef();
}
// Add parentheses to ternary operator where necessary
// TODO: this is only necessary if one typedef simplification had a comma and was used within ?:
// If typedef handling is refactored and moved to symboldatabase someday we can remove this
prepareTernaryOpForAST();
for (Token* tok = list.front(); tok;) {
if (Token::Match(tok, "union|struct|class union|struct|class"))
tok->deleteNext();

View File

@ -8025,6 +8025,8 @@ private:
ASSERT_EQUALS("a ? ( b , c ) : d ;", tokenizeAndStringify("a ? (b , c) : d;"));
ASSERT_EQUALS("a ? ( 1 ? ( a , b ) : 3 ) : d ;", tokenizeAndStringify("a ? 1 ? a, b : 3 : d;"));
ASSERT_EQUALS("a ? ( std :: map < int , int > ( ) ) : 0 ;", tokenizeAndStringify("typedef std::map<int,int> mymap; a ? mymap() : 0;"));
}
std::string testAst(const char code[],bool verbose=false) {