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
7 changes: 7 additions & 0 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 @@ -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("intab{&", testAst("int &a { b };"));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests seem to reflect the status quo, i.e. the AST still contains &, &&, and *.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm weird... it looks good with --debug --verbose so I just copy-pasted from these. Are there parts of the AST that are not printed with those flags?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test code is not tokenized like regular code, especially varids are not set. Maybe ListSimplification::Full would help.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, there is a cyclic AST exception with ListSimplification::Full, so this needs additional work.

ASSERT_EQUALS("inta0{&&", testAst("int &&a { 0 };"));
ASSERT_EQUALS("intanullptr{*", testAst("int *a { nullptr };"));
}

#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