Ticket #8436: Handle C++11 initializations within ternary operator. (#1174)

This commit is contained in:
Simon Martin 2018-04-21 11:30:07 +02:00 committed by Daniel Marjamäki
parent d939c6015a
commit a451a5b598
2 changed files with 7 additions and 1 deletions

View File

@ -599,7 +599,7 @@ static void compileTerm(Token *&tok, AST_state& state)
compileUnaryOp(tok, state, compileExpression);
else
compileBinOp(tok, state, compileExpression);
if (Token::simpleMatch(tok, "} ,")) {
if (Token::Match(tok, "} ,|:")) {
tok = tok->next();
}
} else if (!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) {

View File

@ -74,6 +74,7 @@ private:
TEST_CASE(tokenize33); // #5780 Various crashes on valid template code
TEST_CASE(tokenize34); // #8031
TEST_CASE(tokenize35); // #8361
TEST_CASE(tokenize36); // #8436
TEST_CASE(validate);
@ -850,6 +851,11 @@ private:
"template<typename T> ::CRCWord const Compute(T const t) { return 0; }");
}
void tokenize36() { // #8436
const char code[] = "int foo ( int i ) { return i ? * new int { 5 } : int { i ? 0 : 1 } ; }";
ASSERT_EQUALS(code, tokenizeAndStringify(code));
}
void validate() {
// C++ code in C file
ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,false,Settings::Native,"test.c"), InternalError);