Skip to content

Commit e18b7ba

Browse files
committed
Fix #14085 Add isExplicit attribute to operators
1 parent 4617bc2 commit e18b7ba

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,8 @@ Function::Function(const Token *tok,
25552555
if (::isOperator(tokenDef)) {
25562556
isOperator(true);
25572557

2558+
isExplicit(tokenDef->strAt(-1) == "explicit" || tokenDef->strAt(-2) == "explicit");
2559+
25582560
// 'operator =' is special
25592561
if (tokenDef->str() == "operator=")
25602562
type = FunctionType::eOperatorEqual;

test/testsymboldatabase.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ class TestSymbolDatabase : public TestFixture {
430430
TEST_CASE(symboldatabase109); // #13553
431431
TEST_CASE(symboldatabase110);
432432
TEST_CASE(symboldatabase111); // [[fallthrough]]
433+
TEST_CASE(symboldatabase112); // explicit operator
433434

434435
TEST_CASE(createSymbolDatabaseFindAllScopes1);
435436
TEST_CASE(createSymbolDatabaseFindAllScopes2);
@@ -5841,6 +5842,17 @@ class TestSymbolDatabase : public TestFixture {
58415842
ASSERT(case3 && case3->isAttributeFallthrough());
58425843
}
58435844

5845+
void symboldatabase112() { // explicit operator
5846+
GET_SYMBOL_DB("class S {\n"
5847+
" explicit constexpr operator bool() const noexcept { return ptr_ != nullptr; }\n"
5848+
"private:\n"
5849+
" void *ptr_{nullptr};\n"
5850+
"};\n");
5851+
const Token *f = db ? Token::findsimplematch(tokenizer.tokens(), "operatorbool") : nullptr;
5852+
ASSERT(f != nullptr);
5853+
ASSERT(f && f->function() && f->function()->isExplicit());
5854+
}
5855+
58445856
void createSymbolDatabaseFindAllScopes1() {
58455857
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
58465858
ASSERT(db->scopeList.size() == 3);

0 commit comments

Comments
 (0)