Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// function prototype?
else if (declEnd && declEnd->str() == ";") {
if (tok->astParent() && tok->astParent()->str() == "::" &&
if ((Token::simpleMatch(tok->tokAt(-1), "::") || (tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), ":: ~"))) &&
Token::Match(declEnd->previous(), "default|delete")) {
addClassFunction(scope, tok, argStart);
continue;
Expand Down
7 changes: 4 additions & 3 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,8 +1787,9 @@ static Token * createAstAtToken(Token *tok)
}
}

if (Token::Match(tok, "%type% %name%|*|&|&&|::") && !Token::Match(tok, "return|new|delete")) {
int typecount = 0;
if ((Token::Match(tok, "%type% %name%|*|&|&&|::") && !Token::Match(tok, "return|new|delete")) ||
(Token::Match(tok, ":: %type%") && !tok->next()->isKeyword())) {
int typecount = tok->str() == "::" ? 1 : 0;
Token *typetok = tok;
while (Token::Match(typetok, "%type%|::|*|&|&&|<")) {
if (typetok->isName() && !Token::simpleMatch(typetok->previous(), "::"))
Expand All @@ -1811,7 +1812,7 @@ static Token * createAstAtToken(Token *tok)
!Token::Match(tok, "return|throw") &&
Token::Match(typetok->previous(), "%name% ( !!*") &&
typetok->previous()->varId() == 0 &&
!typetok->previous()->isKeyword() &&
(!typetok->previous()->isKeyword() || typetok->previous()->isOperatorKeyword()) &&
(skipMethodDeclEnding(typetok->link()) || Token::Match(typetok->link(), ") ;|{")))
return typetok;
}
Expand Down
31 changes: 23 additions & 8 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(astrvaluedecl);
TEST_CASE(astorkeyword);
TEST_CASE(astenumdecl);
TEST_CASE(astfuncdecl);

TEST_CASE(startOfExecutableScope);

Expand Down Expand Up @@ -6400,22 +6401,31 @@ class TestTokenizer : public TestFixture {
Z3
};

enum class ListSimplification : std::uint8_t {
Partial,
Full
};

template<size_t size>
std::string testAst(const char (&data)[size], AstStyle style = AstStyle::Simple) {
std::string testAst(const char (&data)[size], AstStyle style = AstStyle::Simple, ListSimplification ls = ListSimplification::Partial) {
// tokenize given code..
TokenList tokenlist{settings0, Standards::Language::CPP};
tokenlist.appendFileIfNew("test.cpp");
if (!tokenlist.createTokensFromString(data))
return "ERROR";

TokenizerTest tokenizer(std::move(tokenlist), *this);
tokenizer.combineStringAndCharLiterals();
tokenizer.combineOperators();
tokenizer.simplifySpaceshipOperator();
tokenizer.createLinks();
tokenizer.createLinks2();
tokenizer.simplifyCAlternativeTokens();
tokenizer.list.front()->assignIndexes();
if (ls == ListSimplification::Partial) {
tokenizer.combineStringAndCharLiterals();
tokenizer.combineOperators();
tokenizer.simplifySpaceshipOperator();
tokenizer.createLinks();
tokenizer.createLinks2();
tokenizer.simplifyCAlternativeTokens();
tokenizer.list.front()->assignIndexes();
} else { // Full
tokenizer.simplifyTokens1("");
}

// set varid..
for (Token *tok = tokenizer.list.front(); tok; tok = tok->next()) {
Expand Down Expand Up @@ -7408,6 +7418,11 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("A0U=", testAst("enum myclass : unsigned char { A = 0U, };"));
}

void astfuncdecl() {
ASSERT_EQUALS("", testAst("bool operator==(const S& a, const S& b);", AstStyle::Simple, ListSimplification::Full));
ASSERT_EQUALS("", testAst("::int32_t f();"));
}

#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