Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2578,8 +2578,6 @@ Function::Function(const Token *tok,
// constructor of any kind
else
type = FunctionType::eConstructor;

isExplicit(tokenDef->strAt(-1) == "explicit" || tokenDef->strAt(-2) == "explicit");
}

const Token *tok1 = setFlags(tok, scope);
Expand Down Expand Up @@ -2653,6 +2651,12 @@ Function::Function(const Token *tok,
isInline(true);
hasBody(true);
}

for (tok = tokenDef->previous(); Token::Match(tok, "&|&&|*|::|)|[|(|]|%name%"); tok = tok->previous()) {
Comment thread
danmar marked this conversation as resolved.
Outdated
// We should set other keywords here as well
if (tok->str() == "explicit")
isExplicit(true);
}
}

Function::Function(const Token *tokenDef, const std::string &clangType)
Expand Down
12 changes: 12 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(symboldatabase109); // #13553
TEST_CASE(symboldatabase110);
TEST_CASE(symboldatabase111); // [[fallthrough]]
TEST_CASE(symboldatabase112); // explicit operator

TEST_CASE(createSymbolDatabaseFindAllScopes1);
TEST_CASE(createSymbolDatabaseFindAllScopes2);
Expand Down Expand Up @@ -5841,6 +5842,17 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(case3 && case3->isAttributeFallthrough());
}

void symboldatabase112() { // explicit operator
GET_SYMBOL_DB("class S {\n"
" explicit constexpr operator bool() const noexcept { return ptr_ != nullptr; }\n"
"private:\n"
" void *ptr_{nullptr};\n"
"};\n");
const Token *f = db ? Token::findsimplematch(tokenizer.tokens(), "operatorbool") : nullptr;
ASSERT(f != nullptr);
ASSERT(f && f->function() && f->function()->isExplicit());
}

void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);
Expand Down