Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,7 @@ void CheckStl::invalidContainer()
if (info.tok->variable()->isReference() && !isVariableDecl(info.tok) &&
reaches(info.tok->variable()->nameToken(), tok, nullptr)) {

if ((assignExpr && Token::Match(assignExpr->astOperand1(), "& %varid%", info.tok->varId())) || // TODO: fix AST
Token::Match(assignExpr, "& %varid% {|(", info.tok->varId())) {
if ((assignExpr && Token::Match(assignExpr->astOperand1()->previous(), "& %varid%", info.tok->varId()))) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ static Token * createAstAtToken(Token *tok)
}
typetok = typetok->next();
}
if (Token::Match(typetok, "%var% =") && typetok->varId())
if ((Token::Match(typetok, "%var% =") || Token::Match(typetok, "%var% {")) && typetok->varId())
tok = typetok;

// Do not create AST for function declaration
Expand Down
31 changes: 19 additions & 12 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(astcompound);
TEST_CASE(astfuncdecl);
TEST_CASE(astarrayinit);
TEST_CASE(astbracedinit);

TEST_CASE(startOfExecutableScope);

Expand Down Expand Up @@ -6522,21 +6523,21 @@ class TestTokenizer : public TestFixture {
tokenizer.createLinks2();
tokenizer.simplifyCAlternativeTokens();
tokenizer.list.front()->assignIndexes();
} else { // Full
tokenizer.simplifyTokens1("");
}

// set varid..
for (Token *tok = tokenizer.list.front(); tok; tok = tok->next()) {
if (tok->str() == "var")
tok->varId(1);
}
// set varid..
for (Token *tok = tokenizer.list.front(); tok; tok = tok->next()) {
if (tok->str() == "var")
tok->varId(1);
}

// Create AST..
tokenizer.prepareTernaryOpForAST();
tokenizer.list.createAst();
// Create AST..
tokenizer.prepareTernaryOpForAST();
tokenizer.list.createAst();

tokenizer.list.validateAst(false);
tokenizer.list.validateAst(false);
} else { // Full
tokenizer.simplifyTokens1("");
}

// Basic AST validation
for (const Token *tok = tokenizer.list.front(); tok; tok = tok->next()) {
Expand Down Expand Up @@ -7535,6 +7536,12 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("a2[2[ 12, 34,{", testAst("int a[2][2]{ { 1, 2 }, { 3, 4 } };"));
}

void astbracedinit() {
ASSERT_EQUALS("ab{", testAst("int &a { b };", AstStyle::Simple, ListSimplification::Full));
ASSERT_EQUALS("a0{", testAst("int &&a { 0 };", AstStyle::Simple, ListSimplification::Full));
ASSERT_EQUALS("anullptr{", testAst("int *a { nullptr };", AstStyle::Simple, ListSimplification::Full));
}

#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
template<size_t size>
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {
Expand Down
Loading