AST: Harden handling of C++11

This commit is contained in:
Daniel Marjamäki 2017-04-10 23:29:15 +02:00
parent 2c43075ece
commit 632a6b664c
2 changed files with 5 additions and 2 deletions

View File

@ -1007,7 +1007,9 @@ static bool isLambdaCaptureList(const Token * tok)
// see compilePrecedence2
if (tok->str() != "[")
return false;
if (Token::simpleMatch(tok->astOperand1(), "{"))
if (!Token::Match(tok->link(), "] (|{"))
return false;
if (Token::simpleMatch(tok->astOperand1(), "{") && tok->astOperand1() == tok->link()->next())
return true;
if (!tok->astOperand1() || tok->astOperand1()->str() != "(")
return false;
@ -1023,7 +1025,7 @@ static Token * createAstAtToken(Token *tok, bool cpp);
static void createAstAtTokenInner(Token * const tok1, const Token *endToken, bool cpp)
{
for (Token *tok = tok1; tok && tok != endToken; tok = tok ? tok->next() : nullptr) {
if (tok->str() == "{") {
if (tok->str() == "{" && !iscpp11init(tok)) {
if (Token::simpleMatch(tok->previous(), "( {"))
;
// struct assignment

View File

@ -8050,6 +8050,7 @@ private:
// TODO: This AST is incomplete however it's very weird syntax (taken from clang test suite)
ASSERT_EQUALS("a&(", testAst("(int (**)[i]){&a}[0][1][5] = 0;"));
ASSERT_EQUALS("n0=", testAst("TrivialDefCtor{[2][2]}[1][1].n = 0;"));
ASSERT_EQUALS("aT12,3,{1[=", testAst("a = T{1, 2, 3}[1];"));
// ({..})
ASSERT_EQUALS("a{+d+ bc+", testAst("a+({b+c;})+d"));