File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -2578,8 +2578,6 @@ Function::Function(const Token *tok,
25782578 // constructor of any kind
25792579 else
25802580 type = FunctionType::eConstructor;
2581-
2582- isExplicit (tokenDef->strAt (-1 ) == " explicit" || tokenDef->strAt (-2 ) == " explicit" );
25832581 }
25842582
25852583 const Token *tok1 = setFlags (tok, scope);
@@ -2653,6 +2651,14 @@ Function::Function(const Token *tok,
26532651 isInline (true );
26542652 hasBody (true );
26552653 }
2654+
2655+ for (tok = tokenDef->previous (); Token::Match (tok, " &|&&|*|::|)|]|%name%" ); tok = tok->previous ()) {
2656+ // We should set other keywords here as well
2657+ if (tok->str () == " explicit" )
2658+ isExplicit (true );
2659+ if (tok->str () == " ]" || tok->str () == " )" )
2660+ tok = tok->link ();
2661+ }
26562662}
26572663
26582664Function::Function (const Token *tokenDef, const std::string &clangType)
Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments