Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,8 @@ Function::Function(const Token *tok,
if (::isOperator(tokenDef)) {
isOperator(true);

isExplicit(tokenDef->strAt(-1) == "explicit" || tokenDef->strAt(-2) == "explicit");
Comment thread
danmar marked this conversation as resolved.
Outdated

// 'operator =' is special
if (tokenDef->str() == "operator=")
type = FunctionType::eOperatorEqual;
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