diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 2e57dfb9f..cffc6e4c0 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -2044,6 +2045,15 @@ std::string Variable::getTypeName() const return ret; } +static bool isOperator(const Token *tokenDef) { + if (!tokenDef) + return false; + if (tokenDef->isOperatorKeyword()) + return true; + const std::string name = tokenDef->str(); + return name.size() > 8 && name.compare(0,8,"operator")==0 && std::strchr("+-*/%&|~^<>!=[(", name[8]); +} + Function::Function(const Tokenizer *mTokenizer, const Token *tok, const Scope *scope, @@ -2067,7 +2077,7 @@ Function::Function(const Tokenizer *mTokenizer, mFlags(0) { // operator function - if (tokenDef->isOperatorKeyword()) { + if (::isOperator(tokenDef)) { isOperator(true); // 'operator =' is special @@ -2215,6 +2225,14 @@ Function::Function(const Token *tokenDef) functionPointerUsage(nullptr), mFlags(0) { + // operator function + if (::isOperator(tokenDef)) { + isOperator(true); + + // 'operator =' is special + if (tokenDef->str() == "operator=") + type = Function::eOperatorEqual; + } } std::string Function::fullName() const diff --git a/test/cli/test-clang-import.py b/test/cli/test-clang-import.py index b54a0f1c9..94cd26df3 100644 --- a/test/cli/test-clang-import.py +++ b/test/cli/test-clang-import.py @@ -94,6 +94,9 @@ def test_symbol_database_3(): def test_symbol_database_4(): check_symbol_database('void f(const int x) {}') +def test_symbol_database_operator(): + check_symbol_database('struct Fred { void operator=(int x); };') + def test_symbol_database_struct_1(): check_symbol_database('struct S {};')