Fixed AST generation if expression starts with ternary operator

This commit is contained in:
PKEuS 2015-02-01 14:01:55 +01:00
parent d6c94e3828
commit f78744ac30
3 changed files with 3 additions and 2 deletions

View File

@ -936,7 +936,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
if (Token::Match(tok, "%type% <") && Token::Match(tok->linkAt(1), "> !!("))
return tok->linkAt(1);
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
Token * const tok1 = tok;
AST_state state(cpp);
compileExpression(tok, state);

View File

@ -2004,7 +2004,7 @@ private:
" some_condition ? 0 : a[i-1];\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Array index -1 is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array index -1 is out of bounds.\n", "", errout.str());
check("void f() {\n"
" int a[10];\n"

View File

@ -8449,6 +8449,7 @@ private:
ASSERT_EQUALS("a0>bc/d:?", testAst("(a>0) ? (b/(c)) : d;"));
ASSERT_EQUALS("abc/+d+", testAst("a + (b/(c)) + d;"));
ASSERT_EQUALS("f( x1024x/0:?", testAst("void f() { x ? 1024 / x : 0; }"));
ASSERT_EQUALS("absizeofd(ef.+(=", testAst("a = b(sizeof(c d) + e.f)"));