From 632a6b664cfc565060b863a5fbac44dc705a5458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 10 Apr 2017 23:29:15 +0200 Subject: [PATCH] AST: Harden handling of C++11 --- lib/tokenlist.cpp | 6 ++++-- test/testtokenize.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 383c04eca..878adf9f0 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c66c5ba18..be28723bd 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"));